<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head>


<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="robots" content="index,nofollow">

<title>AnotherTutorial - wxPyWiki</title>
<script type="text/javascript" src="AnotherTutorial_files/common.js"></script>

<script type="text/javascript">
<!--
var search_hint = "Search";
//-->
</script>


<link rel="stylesheet" type="text/css" charset="utf-8" media="all" href="AnotherTutorial_files/common.css">
<link rel="stylesheet" type="text/css" charset="utf-8" media="screen" href="AnotherTutorial_files/screen.css">
<link rel="stylesheet" type="text/css" charset="utf-8" media="print" href="AnotherTutorial_files/print.css">
<link rel="stylesheet" type="text/css" charset="utf-8" media="projection" href="AnotherTutorial_files/projection.css">

<!-- css only for MS IE6/IE7 browsers -->
<!--[if lt IE 8]>
   <link rel="stylesheet" type="text/css" charset="utf-8" media="all" href="/static/modern/css/msie.css">
<![endif]-->





<link rel="Start" href="http://wiki.wxpython.org/FrontPage">
<link rel="Alternate" title="Wiki Markup" href="http://wiki.wxpython.org/AnotherTutorial?action=raw">
<link rel="Alternate" media="print" title="Print View" href="http://wiki.wxpython.org/AnotherTutorial?action=print">
<link rel="Appendix" title="analogclock.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=analogclock.png">
<link rel="Appendix" title="bargraph.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=bargraph.png">
<link rel="Appendix" title="borders.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=borders.png">
<link rel="Appendix" title="buttons.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=buttons.png">
<link rel="Appendix" title="calculator.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=calculator.png">
<link rel="Appendix" title="calendar.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=calendar.png">
<link rel="Appendix" title="capitals.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=capitals.png">
<link rel="Appendix" title="capitals1.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=capitals1.png">
<link rel="Appendix" title="centraleurope.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=centraleurope.png">
<link rel="Appendix" title="checkbox.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=checkbox.png">
<link rel="Appendix" title="colordialog.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=colordialog.png">
<link rel="Appendix" title="colours.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=colours.png">
<link rel="Appendix" title="combobox.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=combobox.png">
<link rel="Appendix" title="directorydialog.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=directorydialog.png">
<link rel="Appendix" title="dragdrop.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=dragdrop.png">
<link rel="Appendix" title="editor.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=editor.png">
<link rel="Appendix" title="filedialog.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=filedialog.png">
<link rel="Appendix" title="filehunter.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=filehunter.png">
<link rel="Appendix" title="fontdialog.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=fontdialog.png">
<link rel="Appendix" title="fonts.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=fonts.png">
<link rel="Appendix" title="gauge.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=gauge.png">
<link rel="Appendix" title="genbitmaptextbutton.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=genbitmaptextbutton.png">
<link rel="Appendix" title="gray-wolf-gaze.jpg" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=gray-wolf-gaze.jpg">
<link rel="Appendix" title="icon.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=icon.png">
<link rel="Appendix" title="icons.tgz" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=icons.tgz">
<link rel="Appendix" title="images.tgz" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=images.tgz">
<link rel="Appendix" title="isabelle.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=isabelle.png">
<link rel="Appendix" title="kika.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=kika.png">
<link rel="Appendix" title="layout.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=layout.png">
<link rel="Appendix" title="lednumber.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=lednumber.png">
<link rel="Appendix" title="linegraph.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=linegraph.png">
<link rel="Appendix" title="listbox.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=listbox.png">
<link rel="Appendix" title="memento.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=memento.png">
<link rel="Appendix" title="menu1.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=menu1.png">
<link rel="Appendix" title="menu2.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=menu2.png">
<link rel="Appendix" title="messagedialog.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=messagedialog.png">
<link rel="Appendix" title="myconfig.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=myconfig.png">
<link rel="Appendix" title="newt.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=newt.png">
<link rel="Appendix" title="notebook.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=notebook.png">
<link rel="Appendix" title="pagesetupdialog.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=pagesetupdialog.png">
<link rel="Appendix" title="player.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=player.png">
<link rel="Appendix" title="radiobuttons.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=radiobuttons.png">
<link rel="Appendix" title="scattergraph.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=scattergraph.png">
<link rel="Appendix" title="scrolledwindow.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=scrolledwindow.png">
<link rel="Appendix" title="simple.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=simple.png">
<link rel="Appendix" title="singlechoicedialog.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=singlechoicedialog.png">
<link rel="Appendix" title="slider.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=slider.png">
<link rel="Appendix" title="spinctrl.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=spinctrl.png">
<link rel="Appendix" title="spreadsheet.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=spreadsheet.png">
<link rel="Appendix" title="staticbox.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=staticbox.png">
<link rel="Appendix" title="statictext.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=statictext.png">
<link rel="Appendix" title="statusbar.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=statusbar.png">
<link rel="Appendix" title="taskbaricon.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=taskbaricon.png">
<link rel="Appendix" title="textentrydialog.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=textentrydialog.png">
<link rel="Appendix" title="togglebuttons.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=togglebuttons.png">
<link rel="Appendix" title="tom.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=tom.png">
<link rel="Appendix" title="toolbar.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=toolbar.png">
<link rel="Appendix" title="treecontrol.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=treecontrol.png">
<link rel="Appendix" title="wxboxsizer.png" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=wxboxsizer.png">
<link rel="Search" href="http://wiki.wxpython.org/FindPage">
<link rel="Index" href="http://wiki.wxpython.org/TitleIndex">
<link rel="Glossary" href="http://wiki.wxpython.org/WordIndex">
<link rel="Help" href="http://wiki.wxpython.org/HelpOnFormatting">
</head><body dir="ltr" lang="en">

<div id="header">
<div id="logo"><a href="http://wiki.wxpython.org/FrontPage"><img src="AnotherTutorial_files/wxPyWiki.png" alt="wxPyWiki"></a></div>

<form id="searchform" method="get" action="/AnotherTutorial">
<div>
<input name="action" value="fullsearch" type="hidden">
<input name="context" value="180" type="hidden">
<label style="display: none;" for="searchinput">Search:</label>
<input class="disabled" id="searchinput" name="value" value="Search" size="20" onfocus="searchFocus(this)" onblur="searchBlur(this)" onkeyup="searchChange(this)" onchange="searchChange(this)" alt="Search" type="text">
<input disabled="disabled" id="titlesearch" name="titlesearch" value="Titles" alt="Search Titles" type="submit">
<input disabled="disabled" id="fullsearch" name="fullsearch" value="Text" alt="Search Full Text" type="submit">
</div>
</form>
<script type="text/javascript">
<!--// Initialize search form
var f = document.getElementById('searchform');
f.getElementsByTagName('label')[0].style.display = 'none';
var e = document.getElementById('searchinput');
searchChange(e);
searchBlur(e);
//-->
</script>

<ul id="username"><li><a href="http://wiki.wxpython.org/AnotherTutorial?action=login" id="login" rel="nofollow">Login</a></li></ul>
<div id="locationline">


<ul id="pagelocation">
<li><a class="backlink" href="http://wiki.wxpython.org/AnotherTutorial?action=fullsearch&amp;context=180&amp;value=linkto%3A%22AnotherTutorial%22" rel="nofollow" title="Click to do a full-text search for this title">AnotherTutorial</a></li>
</ul>

</div>


<ul id="navibar">
<li class="wikilink"><a href="http://wiki.wxpython.org/FrontPage">FrontPage</a></li><li class="wikilink"><a href="http://wiki.wxpython.org/RecentChanges">RecentChanges</a></li><li class="wikilink"><a href="http://wiki.wxpython.org/SiteNavigation">SiteNavigation</a></li><li class="wikilink"><a href="http://wiki.wxpython.org/FindPage">FindPage</a></li><li class="wikilink"><a href="http://wiki.wxpython.org/HelpContents">HelpContents</a></li><li class="current"><a href="http://wiki.wxpython.org/AnotherTutorial">AnotherTutorial</a></li>
</ul>

<div id="pageline"><hr style="display: none;"></div>

<ul class="editbar"><li><span class="disabled">Immutable Page</span></li><li class="toggleCommentsButton" style="display: none;"><a href="#" class="nbcomment" onclick="toggleComments();return false;">Comments</a></li><li><a class="nbinfo" href="http://wiki.wxpython.org/AnotherTutorial?action=info" rel="nofollow">Info</a></li><li><a class="nbattachments" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile" rel="nofollow">Attachments</a></li><li>
<form class="actionsmenu" method="GET" action="/AnotherTutorial">
<div>
    
    <select name="action" onchange="if ((this.selectedIndex != 0) &amp;&amp;
                      (this.options[this.selectedIndex].disabled == false)) {
                this.form.submit();
            }
            this.selectedIndex = 0;">
        <option selected="selected" value="show">More Actions:</option><option value="raw">Raw Text</option>
<option value="print">Print View</option>
<option value="RenderAsDocbook">Render as Docbook</option>
<option value="refresh">Delete Cache</option>
<option value="show" disabled="disabled" class="disabled">------------------------</option>
<option value="SpellCheck">Check Spelling</option>
<option value="LikePages">Like Pages</option>
<option value="LocalSiteMap">Local Site Map</option>
<option value="show" disabled="disabled" class="disabled">------------------------</option>
<option value="RenamePage" disabled="disabled" class="disabled">Rename Page</option>
<option value="DeletePage" disabled="disabled" class="disabled">Delete Page</option>
<option value="show" disabled="disabled" class="disabled">------------------------</option>
<option value="show" disabled="disabled" class="disabled">Subscribe User</option>
<option value="show" disabled="disabled" class="disabled">------------------------</option>
<option value="show" disabled="disabled" class="disabled">Remove Spam</option>
<option value="show" disabled="disabled" class="disabled">Revert to this revision</option>
<option value="show" disabled="disabled" class="disabled">Package Pages</option>
<option value="SyncPages">Sync Pages</option>
<option value="show" disabled="disabled" class="disabled">------------------------</option>
<option value="Load">Load</option>
<option value="Save">Save</option>
    </select>
    
    
</div>
<script type="text/javascript">
<!--// Init menu
actionsMenuInit('More Actions:');
//-->
</script>
</form>
</li></ul>

</div>

<div id="page" dir="ltr" lang="en">
<div dir="ltr" id="content" lang="en"><span class="anchor" id="top"></span>
<span class="anchor" id="line-1"></span><p class="line867">
</p><h1 id="The_wxPython_Linux_Tutorial">The wxPython Linux Tutorial</h1>
<span class="anchor" id="line-2"></span><p class="line867"><strong>Table of Contents:</strong> <span class="anchor" id="line-3"></span><span class="anchor" id="line-4"></span></p><p class="line867"></p><div class="table-of-contents"><p class="table-of-contents-heading">Contents</p><ol><li>
<a href="#The_wxPython_Linux_Tutorial">The wxPython Linux Tutorial</a><ol><li>
<a href="#Foreword">Foreword</a></li><li>
<a href="#wxPython_API">wxPython API</a></li><li>
<a href="#First_Steps">First Steps</a><ol><li>
<a href="#wx.Window">wx.Window</a></li><li>
<a href="#wx.Frame">wx.Frame</a></li><li>
<a href="#wx.MenuBar">wx.MenuBar</a></li><li>
<a href="#wx.ToolBar">wx.ToolBar</a></li></ol></li><li>
<a href="#Layout__Management">Layout  Management</a><ol><li>
<a href="#wx.BoxSizer">wx.BoxSizer</a></li><li>
<a href="#wx.GridSizer">wx.GridSizer</a></li><li>
<a href="#wx.GridBagSizer">wx.GridBagSizer</a></li></ol></li><li>
<a href="#Basic_Objects">Basic Objects</a><ol><li>
<a href="#Cursors">Cursors</a></li><li>
<a href="#Fonts">Fonts</a></li><li>
<a href="#Colours">Colours</a></li><li>
<a href="#Bitmaps">Bitmaps</a></li></ol></li><li>
<a href="#Events">Events</a><ol><li>
<a href="#Examples">Examples</a></li></ol></li><li>
<a href="#Dialogs">Dialogs</a><ol><li>
<a href="#Custom_dialogs">Custom dialogs</a></li><li>
<a href="#Common_Predefined_Dialogs">Common Predefined Dialogs</a></li></ol></li><li>
<a href="#Core_Widgets">Core Widgets</a><ol><li>
<a href="#wx.Button">wx.Button</a></li><li>
<a href="#wx.ToggleButton">wx.ToggleButton</a></li><li>
<a href="#wx.BitmapButton">wx.BitmapButton</a></li><li>
<a href="#wx.StaticLine">wx.StaticLine</a></li><li>
<a href="#wx.StaticText">wx.StaticText</a></li><li>
<a href="#wx.StaticBox">wx.StaticBox</a></li><li>
<a href="#wx.ComboBox">wx.ComboBox</a></li><li>
<a href="#wx.CheckBox">wx.CheckBox</a></li><li>
<a href="#wx.StatusBar">wx.StatusBar</a></li><li>
<a href="#wx.RadioButton">wx.RadioButton</a></li><li>
<a href="#wx.Gauge">wx.Gauge</a></li><li>
<a href="#wx.Slider">wx.Slider</a></li><li>
<a href="#wx.ListBox">wx.ListBox</a></li><li>
<a href="#wx.SpinCtrl">wx.SpinCtrl</a></li><li>
<a href="#wx.ListCtrl">wx.ListCtrl</a></li><li>
<a href="#wx.SplitterWindow">wx.SplitterWindow</a></li><li>
<a href="#wx.ScrolledWindow">wx.ScrolledWindow</a></li><li>
<a href="#wx.TreeCtrl">wx.TreeCtrl</a></li><li>
<a href="#wx.Notebook">wx.Notebook</a></li></ol></li><li>
<a href="#wx.lib_Classes">wx.lib Classes</a><ol><li>
<a href="#Mouse_Gestures">Mouse Gestures</a></li><li>
<a href="#AnalogClockWindow">AnalogClockWindow</a></li><li>
<a href="#Bitmap_Text_Buttons">Bitmap Text Buttons</a></li></ol></li><li>
<a href="#Advanced_Widgets">Advanced Widgets</a><ol><li>
<a href="#CalendarCtrl">CalendarCtrl</a></li><li>
<a href="#LEDNumberCtrl">LEDNumberCtrl</a></li></ol></li><li>
<a href="#Creating_a_taskbar_application">Creating a taskbar application</a></li><li>
<a href="#wx.TheClipboard">wx.TheClipboard</a></li><li>
<a href="#Drag_and_Drop">Drag and Drop</a></li><li>
<a href="#Plotting">Plotting</a></li><li>
<a href="#Configuring_application_settings">Configuring application settings</a></li><li>
<a href="#wxPython_functions">wxPython functions</a><ol><li>
<a href="#System_functions">System functions</a></li><li>
<a href="#Dialog_functions">Dialog functions</a></li><li>
<a href="#Other_functions">Other functions</a></li></ol></li><li>
<a href="#Using_xml_resource_files">Using xml resource files</a></li><li>
<a href="#Skeletons">Skeletons</a><ol><li>
<a href="#File_Hunter">File Hunter</a></li><li>
<a href="#SpreadSheet">SpreadSheet</a></li></ol></li><li>
<a href="#Tips_And_Tricks">Tips And Tricks</a><ol><li>
<a href="#PopupMenu">PopupMenu</a></li><li>
<a href="#The_tiniest_wxPython_application">The tiniest wxPython application</a></li><li>
<a href="#Interactive_Button">Interactive Button</a></li><li>
<a href="#Error_handling_without_dialogs">Error handling without dialogs</a></li><li>
<a href="#UndoRedoFramework">UndoRedoFramework</a></li></ol></li><li>
<a href="#Gripts">Gripts</a><ol><li>
<a href="#Tom">Tom</a></li><li>
<a href="#Editor">Editor</a></li><li>
<a href="#Kika">Kika</a></li></ol></li><li>
<a href="#Appendix">Appendix</a><ol><li>
<a href="#Cursor_IDs">Cursor IDs</a></li><li>
<a href="#wx.Frame_styles">wx.Frame styles</a></li><li>
<a href="#Standard_Colour_Database">Standard Colour Database</a></li><li>
<a href="#wx.Pen_styles">wx.Pen styles</a></li><li>
<a href="#wx.Brush_styles">wx.Brush styles</a></li><li>
<a href="#CalendarCtrl_styles">CalendarCtrl styles</a></li><li>
<a href="#Keycodes">Keycodes</a></li></ol></li><li>
<a href="#Comments...">Comments...</a></li></ol></li></ol></div> <span class="anchor" id="line-5"></span><span class="anchor" id="line-6"></span><p class="line867">
</p><h2 id="Foreword">Foreword</h2>
<span class="anchor" id="line-7"></span><p class="line874">The purpose 
of this tutorial is to get you started with the wxPython toolkit, from 
the basics to the advanced topics. It has lots of code examples, not 
much talking. After that, you will be able to dig in yourself. <span class="anchor" id="line-8"></span><span class="anchor" id="line-9"></span></p><ul><li>mailing list <span class="anchor" id="line-10"></span></li><li>reference book <span class="anchor" id="line-11"></span></li><li>source code of wxPython applications <span class="anchor" id="line-12"></span></li><li>/home/vronskij/bin/wxPython/usr/lib/python2.4/site-packages/wx-2.6-gtk2-unicode/wx - the ultimate resource, on my Linux box <span class="anchor" id="line-13"></span><span class="anchor" id="line-14"></span></li></ul><p class="line874">There are three decent toolkits for the python programming language: <span class="anchor" id="line-15"></span><span class="anchor" id="line-16"></span></p><ul><li><p class="line891"><tt>wxPython</tt> <span class="anchor" id="line-17"></span></p></li><li><p class="line891"><tt>PyQt</tt> <span class="anchor" id="line-18"></span></p></li><li><p class="line891"><tt>PyGTK</tt> <span class="anchor" id="line-19"></span><span class="anchor" id="line-20"></span></p></li></ul><p class="line874">Note that this tutorial is done on Linux. Some scripts do not work correctly on windows. <span class="anchor" id="line-21"></span><span class="anchor" id="line-22"></span></p><p class="line862">Icons used in this tutorial: <a class="attachment" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=icons.tgz" title="attachment:icons.tgz">icons.tgz</a> Images used in this tutorial: <a class="attachment" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile&amp;do=view&amp;target=images.tgz" title="attachment:images.tgz">images.tgz</a> <span class="anchor" id="line-23"></span><span class="anchor" id="line-24"></span></p><p class="line874">jan bodnar 2005 - 2007 <span class="anchor" id="line-25"></span><span class="anchor" id="line-26"></span></p><p class="line862">status update. (april 2007) All my work on wxPython tutorial has been moved to my website <a class="http" href="http://www.zetcode.com/wxpython">http://www.zetcode.com/wxpython</a> here I shall not add any more examples. If I find myself some time, I will do some polishing. <span class="anchor" id="line-27"></span><span class="anchor" id="line-28"></span></p><p class="line867">
</p><h2 id="wxPython_API">wxPython API</h2>
<span class="anchor" id="line-29"></span><p class="line874">wxPython API
 is a set of functions and widgets. Widgets are essential building 
blocks of a GUI application. Under Windows widgets are calles controls. 
We can roughly divide programmers into two groups. They code 
applications or libraries. In our case, wxPython is  a library that is 
used by application programmers to code applications. Technically, 
wxPython is a wrapper over a C++ GUI API called wxWidgets. So it is not a
 native API. e.g. not written  directly in Python. The only native GUI 
library for an interpreted language that I know is Java's Swing library.
 <span class="anchor" id="line-30"></span><span class="anchor" id="line-31"></span></p><p class="line874">In wxPython we have lot's of widgets. These can be divided into some logical groups. <span class="anchor" id="line-32"></span><span class="anchor" id="line-33"></span></p><p class="line867"><strong>Base Widgets</strong> <span class="anchor" id="line-34"></span><span class="anchor" id="line-35"></span></p><p class="line874">These widgets provide basic functionality for derived widgets. They are usually not used directly. <span class="anchor" id="line-36"></span><span class="anchor" id="line-37"></span></p><ul><li><p class="line891"><tt>wx.Window</tt> <span class="anchor" id="line-38"></span></p></li><li><p class="line891"><tt>wx.Control</tt> <span class="anchor" id="line-39"></span></p></li><li><p class="line891"><tt>wx.ControlWithItem</tt> <span class="anchor" id="line-40"></span><span class="anchor" id="line-41"></span></p></li></ul><p class="line867"><strong>Top level Widgets</strong> <span class="anchor" id="line-42"></span><span class="anchor" id="line-43"></span></p><p class="line874">These widgets exist independently of each other. <span class="anchor" id="line-44"></span><span class="anchor" id="line-45"></span></p><ul><li><p class="line891"><tt>wx.Frame</tt> <span class="anchor" id="line-46"></span></p></li><li><p class="line891"><tt>wx.MDIParentFrame</tt> <span class="anchor" id="line-47"></span></p></li><li><p class="line891"><tt>wx.MDIChildFrame</tt> <span class="anchor" id="line-48"></span></p></li><li><p class="line891"><tt>wx.Dialog</tt> <span class="anchor" id="line-49"></span></p></li><li><p class="line891"><tt>wx.PopupWindow</tt> <span class="anchor" id="line-50"></span><span class="anchor" id="line-51"></span></p></li></ul><p class="line867"><strong>Containers</strong> <span class="anchor" id="line-52"></span><span class="anchor" id="line-53"></span></p><p class="line874">Containers contain other widgets. These widgets are called children. <span class="anchor" id="line-54"></span><span class="anchor" id="line-55"></span></p><ul><li><p class="line891"><tt>wx.Panel</tt> <span class="anchor" id="line-56"></span></p></li><li><p class="line891"><tt>wx.Notebook</tt> <span class="anchor" id="line-57"></span></p></li><li><p class="line891"><tt>wx.ScrolledWindow</tt> <span class="anchor" id="line-58"></span></p></li><li><p class="line891"><tt>wx.SplitterWindow</tt> <span class="anchor" id="line-59"></span><span class="anchor" id="line-60"></span></p></li></ul><p class="line867"><strong>Dynamic Widgets</strong> <span class="anchor" id="line-61"></span><span class="anchor" id="line-62"></span></p><p class="line874">These widgets can be edited by users. <span class="anchor" id="line-63"></span><span class="anchor" id="line-64"></span></p><ul><li><p class="line891"><tt>wx.Button</tt> <span class="anchor" id="line-65"></span></p></li><li><p class="line891"><tt>wx.BitmapButton</tt> <span class="anchor" id="line-66"></span></p></li><li><p class="line891"><tt>wx.Choice</tt> <span class="anchor" id="line-67"></span></p></li><li><p class="line891"><tt>wx.ComboBox</tt> <span class="anchor" id="line-68"></span></p></li><li><p class="line891"><tt>wx.CheckBox</tt> <span class="anchor" id="line-69"></span></p></li><li><p class="line891"><tt>wx.Grid</tt> <span class="anchor" id="line-70"></span></p></li><li><p class="line891"><tt>wx.ListBox</tt> <span class="anchor" id="line-71"></span></p></li><li><p class="line891"><tt>wx.RadioBox</tt> <span class="anchor" id="line-72"></span></p></li><li><p class="line891"><tt>wx.RadioButton</tt> <span class="anchor" id="line-73"></span></p></li><li><p class="line891"><tt>wx.ScrollBar</tt> <span class="anchor" id="line-74"></span></p></li><li><p class="line891"><tt>wx.SpinButton</tt> <span class="anchor" id="line-75"></span></p></li><li><p class="line891"><tt>wx.SpinCtrl</tt> <span class="anchor" id="line-76"></span></p></li><li><p class="line891"><tt>wx.Slider</tt> <span class="anchor" id="line-77"></span></p></li><li><p class="line891"><tt>wx.TextCtrl</tt> <span class="anchor" id="line-78"></span></p></li><li><p class="line891"><tt>wx.ToggleButton</tt> <span class="anchor" id="line-79"></span><span class="anchor" id="line-80"></span></p></li></ul><p class="line867"><strong>Static Widgets</strong> <span class="anchor" id="line-81"></span><span class="anchor" id="line-82"></span></p><p class="line874">These widgets display informatin. They cannot be edited by user. <span class="anchor" id="line-83"></span><span class="anchor" id="line-84"></span></p><ul><li><p class="line891"><tt>wx.Gauge</tt> <span class="anchor" id="line-85"></span></p></li><li><p class="line891"><tt>wx.StaticText</tt> <span class="anchor" id="line-86"></span></p></li><li><p class="line891"><tt>wx.StaticBitmap</tt> <span class="anchor" id="line-87"></span></p></li><li><p class="line891"><tt>wx.StaticLine</tt> <span class="anchor" id="line-88"></span></p></li><li><p class="line891"><tt>wx.StaticBox</tt> <span class="anchor" id="line-89"></span><span class="anchor" id="line-90"></span></p></li></ul><p class="line867"><strong>Other Widgets</strong> <span class="anchor" id="line-91"></span><span class="anchor" id="line-92"></span></p><p class="line874">These widgets implement statusbar, toolbar and menubar in an application. <span class="anchor" id="line-93"></span><span class="anchor" id="line-94"></span></p><ul><li><p class="line891"><tt>wx.MenuBar</tt> <span class="anchor" id="line-95"></span></p></li><li><p class="line891"><tt>wx.ToolBar</tt> <span class="anchor" id="line-96"></span></p></li><li><p class="line891"><tt>wx.StatusBar</tt> <span class="anchor" id="line-97"></span><span class="anchor" id="line-98"></span></p></li></ul><p class="line867">
</p><h2 id="First_Steps">First Steps</h2>
<span class="anchor" id="line-99"></span><p class="line874">We start with a simple example. <span class="anchor" id="line-100"></span><span class="anchor" id="line-101"></span></p><p class="line867"><span class="anchor" id="line-102"></span><span class="anchor" id="line-103"></span><span class="anchor" id="line-104"></span><span class="anchor" id="line-105"></span><span class="anchor" id="line-106"></span><span class="anchor" id="line-107"></span><span class="anchor" id="line-108"></span><span class="anchor" id="line-109"></span><span class="anchor" id="line-110"></span><span class="anchor" id="line-111"></span><span class="anchor" id="line-112"></span><span class="anchor" id="line-113"></span><span class="anchor" id="line-114"></span><span class="anchor" id="line-115"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
function isnumbered(obj) {
  return obj.childNodes.length && obj.firstChild.childNodes.length && obj.firstChild.firstChild.className == 'LineNumber';
}
function nformat(num,chrs,add) {
  var nlen = Math.max(0,chrs-(''+num).length), res = '';
  while (nlen>0) { res += ' '; nlen-- }
  return res+num+add;
}
function addnumber(did, nstart, nstep) {
  var c = document.getElementById(did), l = c.firstChild, n = 1;
  if (!isnumbered(c))
    if (typeof nstart == 'undefined') nstart = 1;
    if (typeof nstep  == 'undefined') nstep = 1;
    n = nstart;
    while (l != null) {
      if (l.tagName == 'SPAN') {
        var s = document.createElement('SPAN');
        s.className = 'LineNumber'
        s.appendChild(document.createTextNode(nformat(n,4,' ')));
        n += nstep;
        if (l.childNodes.length)
          l.insertBefore(s, l.firstChild)
        else
          l.appendChild(s)
      }
      l = l.nextSibling;
    }
  return false;
}
function remnumber(did) {
  var c = document.getElementById(did), l = c.firstChild;
  if (isnumbered(c))
    while (l != null) {
      if (l.tagName == 'SPAN' && l.firstChild.className == 'LineNumber') l.removeChild(l.firstChild);
      l = l.nextSibling;
    }
  return false;
}
function togglenumber(did, nstart, nstep) {
  var c = document.getElementById(did);
  if (isnumbered(c)) {
    remnumber(did);
  } else {
    addnumber(did,nstart,nstep);
  }
  return false;
}
</script>

<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-194ad950f1ce08e354e1f21b603944c92bbe96b9\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-194ad950f1ce08e354e1f21b603944c92bbe96b9', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-194ad950f1ce08e354e1f21b603944c92bbe96b9" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># simple.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">   8 </span></span>
<span class="line"><span class="LineNumber">   9 </span><span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'simple.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  10 </span><span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  11 </span></span>
<span class="line"><span class="LineNumber">  12 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-116"></span><p class="line874">In every wxPython application, we must import the wx library. <span class="anchor" id="line-117"></span><span class="anchor" id="line-118"></span></p><p class="line867"><span class="anchor" id="line-119"></span><span class="anchor" id="line-120"></span></p><pre>import wx</pre><span class="anchor" id="line-121"></span><p class="line862">An application object is created by initiating class <tt>wx.App</tt>. <span class="anchor" id="line-122"></span><span class="anchor" id="line-123"></span></p><p class="line867"><span class="anchor" id="line-124"></span><span class="anchor" id="line-125"></span></p><pre>app = wx.App()</pre><span class="anchor" id="line-126"></span><p class="line874">We create a frame widget. The window pops up only if we call Show() method on a widget. <span class="anchor" id="line-127"></span><span class="anchor" id="line-128"></span></p><p class="line867"><span class="anchor" id="line-129"></span><span class="anchor" id="line-130"></span><span class="anchor" id="line-131"></span></p><pre>frame = wx.Frame(None, -1, "simple.py")
frame.Show()</pre><span class="anchor" id="line-132"></span><p class="line874">The
 last line enters a Mainloop. A mainloop is an endless cycle that 
catches up all events coming up to your application. It is an integral 
part of any windows GUI application. <span class="anchor" id="line-133"></span><span class="anchor" id="line-134"></span></p><p class="line867"><span class="anchor" id="line-135"></span><span class="anchor" id="line-136"></span></p><pre>app.MainLoop()</pre><span class="anchor" id="line-137"></span><p class="line874">Although
 the code is very simple, you can do a lot of things with your window. 
You can maximize it, minimize it, move it, resize it. All these things 
have been already done. <span class="anchor" id="line-138"></span><span class="anchor" id="line-139"></span></p><p class="line867"><img alt="simple.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_030.png" title="simple.png"> <span class="anchor" id="line-140"></span><span class="anchor" id="line-141"></span></p><p class="line867"><strong>Figure: simple.py</strong> <span class="anchor" id="line-142"></span><span class="anchor" id="line-143"></span></p><p class="line867">
</p><h3 id="wx.Window">wx.Window</h3>
<span class="anchor" id="line-144"></span><p class="line874">wx.Window 
is a base class out of which many widgets inherit. For instance, the 
wx.Frame widget inherits from wx.Window. Technically it means that we 
can use wx.Window's methods for all descendants. We will introduce here 
some of it's methods. <span class="anchor" id="line-145"></span><span class="anchor" id="line-146"></span></p><ul><li><p class="line891"><tt>SetTitle(string&nbsp;title)</tt> - Sets the window's title. Applicable only to frames and dialogs. <span class="anchor" id="line-147"></span></p></li><li><p class="line891"><tt>SetToolTip(wx.ToolTip&nbsp;tip)</tt> - Attaches a tooltip to the window. <span class="anchor" id="line-148"></span></p></li><li><p class="line891"><tt>SetSize(wx.Size&nbsp;size)</tt> - Sets the size of the window. <span class="anchor" id="line-149"></span></p></li><li><p class="line891"><tt>SetPosition(wx.Point&nbsp;pos)</tt> - Positions the window to given coordinates <span class="anchor" id="line-150"></span></p></li><li><p class="line891"><tt>Show(show=True)</tt> - Shows or hides the window. show parameter can be True or False. <span class="anchor" id="line-151"></span></p></li><li><p class="line891"><tt>Move(wx.Point&nbsp;pos)</tt> - Moves the window to the given position. <span class="anchor" id="line-152"></span></p></li><li><p class="line891"><tt>SetCursor(wx.StockCursor&nbsp;id)</tt> - Sets the window's cursor. <span class="anchor" id="line-153"></span><span class="anchor" id="line-154"></span></p></li></ul><p class="line867"><span class="anchor" id="line-155"></span><span class="anchor" id="line-156"></span><span class="anchor" id="line-157"></span><span class="anchor" id="line-158"></span><span class="anchor" id="line-159"></span><span class="anchor" id="line-160"></span><span class="anchor" id="line-161"></span><span class="anchor" id="line-162"></span><span class="anchor" id="line-163"></span><span class="anchor" id="line-164"></span><span class="anchor" id="line-165"></span><span class="anchor" id="line-166"></span><span class="anchor" id="line-167"></span><span class="anchor" id="line-168"></span><span class="anchor" id="line-169"></span><span class="anchor" id="line-170"></span><span class="anchor" id="line-171"></span><span class="anchor" id="line-172"></span><span class="anchor" id="line-173"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-83fbe36c7c2aa9d40e0cc2a3e43102172e499714\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-83fbe36c7c2aa9d40e0cc2a3e43102172e499714', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-83fbe36c7c2aa9d40e0cc2a3e43102172e499714" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># simple2.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">   8 </span></span>
<span class="line"><span class="LineNumber">   9 </span><span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  10 </span><span class="ID">frame</span><span class="Operator">.</span><span class="ID">SetToolTip</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">ToolTip</span><span class="Operator">(</span><span class="String">'This is a frame'</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  11 </span><span class="ID">frame</span><span class="Operator">.</span><span class="ID">SetCursor</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">StockCursor</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">CURSOR_MAGNIFIER</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  12 </span><span class="ID">frame</span><span class="Operator">.</span><span class="ID">SetPosition</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Point</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">,</span><span class="Number">0</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span><span class="ID">frame</span><span class="Operator">.</span><span class="ID">SetSize</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Size</span><span class="Operator">(</span><span class="Number">300</span><span class="Operator">,</span><span class="Number">250</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span><span class="ID">frame</span><span class="Operator">.</span><span class="ID">SetTitle</span><span class="Operator">(</span><span class="String">'simple2.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span><span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span></span>
<span class="line"><span class="LineNumber">  17 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-174"></span><p class="line862">We create a 'This is a frame' tooltip. The cursor is set to a magnifier cursor. Possible cursor id's: <a href="http://wiki.wxpython.org/AnotherTutorial#head-ba098791be2c102e4c44bd330ce13c25a78764d2">are listed below</a> We position the window to the upper left corner and size it to 300x250 pixels. Title is set to 'simple2.py'. <span class="anchor" id="line-175"></span><span class="anchor" id="line-176"></span></p><p class="line867">
</p><h3 id="wx.Frame">wx.Frame</h3>
<span class="anchor" id="line-177"></span><p class="line874">wx.Frame is a container widget.  It means that it can contain other widgets. It has the following constructor: <span class="anchor" id="line-178"></span><span class="anchor" id="line-179"></span></p><p class="line867"><span class="anchor" id="line-180"></span><span class="anchor" id="line-181"></span><span class="anchor" id="line-182"></span><span class="anchor" id="line-183"></span></p><pre>wx.Frame(wx.Window parent, id, string title,
         wx.Point pos = wx.DefaultPosition, wx.Size size = wx.DefaultSize,
         style = wx.DEFAULT_FRAME_STYLE, string name = 'frame')</pre><span class="anchor" id="line-184"></span><p class="line874">A
 constructor is a special kind of a function. It is called when an 
object is created. For us it is only important that when we want to 
create a new widget, we simply call it's constructor.  Python enables 
parameters with default values.  So the only obligatory parameters in 
wx.Frame are parent, id and title. If you specify all values of the 
parameters in order, you don't need to specify the parameter names. For 
example you want to create a wx.Frame widget, which has no parent, it's 
identifier is 100, the title is 'Title', the position is (100,50) and 
the size is (100,100). <span class="anchor" id="line-185"></span><span class="anchor" id="line-186"></span></p><p class="line867"><span class="anchor" id="line-187"></span><span class="anchor" id="line-188"></span></p><pre>frame = wx.Frame(None, 100, 'Title', wx.Point(100,50), wx.Size(100,100))</pre><span class="anchor" id="line-189"></span><p class="line874">Here we have omitted the pos parameter. So we must provide explicitly the size parameter. <span class="anchor" id="line-190"></span><span class="anchor" id="line-191"></span></p><p class="line867"><span class="anchor" id="line-192"></span><span class="anchor" id="line-193"></span></p><pre>frame = wx.Frame(None, 100, 'Title', size = wx.Size(100,100))</pre><span class="anchor" id="line-194"></span><p class="line874">In the following example we will use other useful features. <span class="anchor" id="line-195"></span><span class="anchor" id="line-196"></span></p><p class="line867"><span class="anchor" id="line-197"></span><span class="anchor" id="line-198"></span><span class="anchor" id="line-199"></span><span class="anchor" id="line-200"></span><span class="anchor" id="line-201"></span><span class="anchor" id="line-202"></span><span class="anchor" id="line-203"></span><span class="anchor" id="line-204"></span><span class="anchor" id="line-205"></span><span class="anchor" id="line-206"></span><span class="anchor" id="line-207"></span><span class="anchor" id="line-208"></span><span class="anchor" id="line-209"></span><span class="anchor" id="line-210"></span><span class="anchor" id="line-211"></span><span class="anchor" id="line-212"></span><span class="anchor" id="line-213"></span><span class="anchor" id="line-214"></span><span class="anchor" id="line-215"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-cad39d76e2486958757e3ae6709e4119953d3aa3\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-cad39d76e2486958757e3ae6709e4119953d3aa3', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-cad39d76e2486958757e3ae6709e4119953d3aa3" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># icon.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ResWord">def</span> <span class="ID">main</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   8 </span>    <span class="ID">app</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">   9 </span></span>
<span class="line"><span class="LineNumber">  10 </span>    <span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">=</span><span class="String">'Icon'</span><span class="Operator">,</span> <span class="ID">pos</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">350</span><span class="Operator">,</span><span class="Number">300</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  11 </span>    <span class="ID">frame</span><span class="Operator">.</span><span class="ID">SetIcon</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Icon</span><span class="Operator">(</span><span class="String">'tipi.ico'</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BITMAP_TYPE_ICO</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  12 </span>    <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Center</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span>    <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>    <span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span></span>
<span class="line"><span class="LineNumber">  16 </span><span class="ResWord">if</span> <span class="ID">__name__</span> <span class="Operator">==</span> <span class="String">'__main__'</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  17 </span>    <span class="ID">main</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-216"></span><p class="line874">Icon's
 name is Tipi.ico. The icon is located in current  directory. First 
parameter of an icon's constructor is the file name. Second parameter 
specifies the file type. <span class="anchor" id="line-217"></span><span class="anchor" id="line-218"></span></p><p class="line862">As you have noticed, the structure of our application has changed.  This is a standard in Python programs. In Python programs <span class="u">name</span>
 is a special variable. More complicated programs consist of several 
files. There is usually only one file, which launches the application. 
For this file, Python sets the <span class="u">name</span> variable to  '<span class="u">main</span>'.
  This happens when you launch an application from the command line or 
when you click on the file. So when you click on the icon.py file or you
 launch it from the command line, the <span class="u">name</span> variable equals <span class="u">main</span>. Then function main() is called. <span class="anchor" id="line-219"></span><span class="anchor" id="line-220"></span></p><p class="line867"><img alt="icon.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_049.png" title="icon.png"> <span class="anchor" id="line-221"></span><span class="anchor" id="line-222"></span></p><p class="line867"><strong>Figure: icon.py</strong> <span class="anchor" id="line-223"></span><span class="anchor" id="line-224"></span></p><p class="line867">
</p><h3 id="wx.MenuBar">wx.MenuBar</h3>
<span class="anchor" id="line-225"></span><p class="line874">To set up a
 menubar in your wxPython application is pretty simple. We will discuss 
adding menus to menubar, adding submenus to existing menus. Each menu 
consists of menuitems. Menuitems can be normal items, check items or 
radio items. <span class="anchor" id="line-226"></span><span class="anchor" id="line-227"></span></p><p class="line874">First thing  to do is to create a menubar. <span class="anchor" id="line-228"></span><span class="anchor" id="line-229"></span></p><p class="line867"><span class="anchor" id="line-230"></span><span class="anchor" id="line-231"></span></p><pre>menubar = wx.MenuBar()</pre><span class="anchor" id="line-232"></span><p class="line874">Then we create our menus. <span class="anchor" id="line-233"></span><span class="anchor" id="line-234"></span></p><p class="line867"><span class="anchor" id="line-235"></span><span class="anchor" id="line-236"></span><span class="anchor" id="line-237"></span><span class="anchor" id="line-238"></span></p><pre>file = wx.Menu()
edit = wx.Menu()
help = wx.Menu()</pre><span class="anchor" id="line-239"></span><p class="line874">Then we add some items into the menu. This can be done in two ways. <span class="anchor" id="line-240"></span><span class="anchor" id="line-241"></span></p><p class="line867"><span class="anchor" id="line-242"></span><span class="anchor" id="line-243"></span><span class="anchor" id="line-244"></span></p><pre>file.Append(101, '&amp;Open', 'Open a new document')
file.Append(102, '&amp;Save', 'Save the document')</pre><span class="anchor" id="line-245"></span><p class="line874">We can separate logical sections in menus with a horizontal line. <span class="anchor" id="line-246"></span><span class="anchor" id="line-247"></span></p><p class="line867"><span class="anchor" id="line-248"></span><span class="anchor" id="line-249"></span></p><pre>file.AppendSeparator()</pre><span class="anchor" id="line-250"></span><p class="line862">If you want to have some icons in your menus, you need to create <tt>MenuItem</tt> objects manually. <span class="anchor" id="line-251"></span><span class="anchor" id="line-252"></span></p><p class="line867"><span class="anchor" id="line-253"></span><span class="anchor" id="line-254"></span><span class="anchor" id="line-255"></span><span class="anchor" id="line-256"></span></p><pre>quit = wx.MenuItem(file, 105, '&amp;Quit\tCtrl+Q', 'Quit the Application')
quit.SetBitmap(wx.Image('stock_exit-16.png',wx.BITMAP_TYPE_PNG).ConvertToBitmap())
file.AppendItem(quit)</pre><span class="anchor" id="line-257"></span><p class="line874">wxPython toolkit can only put bitmaps into menus. Therefore we need to convert our PNG files into bitmaps. <span class="anchor" id="line-258"></span><span class="anchor" id="line-259"></span></p><p class="line874">Menus are then added into the menubar. <span class="anchor" id="line-260"></span><span class="anchor" id="line-261"></span></p><p class="line867"><span class="anchor" id="line-262"></span><span class="anchor" id="line-263"></span><span class="anchor" id="line-264"></span><span class="anchor" id="line-265"></span></p><pre>menubar.Append(file, '&amp;File')
menubar.Append(edit, '&amp;Edit')
menubar.Append(help, '&amp;Help')</pre><span class="anchor" id="line-266"></span><p class="line874">Finally we set up our menubar in our application class. <span class="anchor" id="line-267"></span><span class="anchor" id="line-268"></span></p><p class="line867"><span class="anchor" id="line-269"></span><span class="anchor" id="line-270"></span></p><pre>self.SetMenuBar(menubar)</pre><span class="anchor" id="line-271"></span><p class="line874">Let's sum it up in a small script. <span class="anchor" id="line-272"></span><span class="anchor" id="line-273"></span></p><p class="line867"><span class="anchor" id="line-274"></span><span class="anchor" id="line-275"></span><span class="anchor" id="line-276"></span><span class="anchor" id="line-277"></span><span class="anchor" id="line-278"></span><span class="anchor" id="line-279"></span><span class="anchor" id="line-280"></span><span class="anchor" id="line-281"></span><span class="anchor" id="line-282"></span><span class="anchor" id="line-283"></span><span class="anchor" id="line-284"></span><span class="anchor" id="line-285"></span><span class="anchor" id="line-286"></span><span class="anchor" id="line-287"></span><span class="anchor" id="line-288"></span><span class="anchor" id="line-289"></span><span class="anchor" id="line-290"></span><span class="anchor" id="line-291"></span><span class="anchor" id="line-292"></span><span class="anchor" id="line-293"></span><span class="anchor" id="line-294"></span><span class="anchor" id="line-295"></span><span class="anchor" id="line-296"></span><span class="anchor" id="line-297"></span><span class="anchor" id="line-298"></span><span class="anchor" id="line-299"></span><span class="anchor" id="line-300"></span><span class="anchor" id="line-301"></span><span class="anchor" id="line-302"></span><span class="anchor" id="line-303"></span><span class="anchor" id="line-304"></span><span class="anchor" id="line-305"></span><span class="anchor" id="line-306"></span><span class="anchor" id="line-307"></span><span class="anchor" id="line-308"></span><span class="anchor" id="line-309"></span><span class="anchor" id="line-310"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-ff45d9413007cb877809bc6894f1ee9e8db0e33f\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-ff45d9413007cb877809bc6894f1ee9e8db0e33f', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-ff45d9413007cb877809bc6894f1ee9e8db0e33f" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># menu1.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ResWord">class</span> <span class="ID">MyMenu</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   8 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">DefaultPosition</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Size</span><span class="Operator">(</span><span class="Number">200</span><span class="Operator">,</span> <span class="Number">150</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  10 </span></span>
<span class="line"><span class="LineNumber">  11 </span>        <span class="ID">menubar</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MenuBar</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">file</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Menu</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">edit</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Menu</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">help</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Menu</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">file</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="Number">101</span><span class="Operator">,</span> <span class="String">'&amp;Open'</span><span class="Operator">,</span> <span class="String">'Open a new document'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span>        <span class="ID">file</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="Number">102</span><span class="Operator">,</span> <span class="String">'&amp;Save'</span><span class="Operator">,</span> <span class="String">'Save the document'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="ID">file</span><span class="Operator">.</span><span class="ID">AppendSeparator</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  18 </span>        <span class="ID">quit</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MenuItem</span><span class="Operator">(</span><span class="ID">file</span><span class="Operator">,</span> <span class="Number">105</span><span class="Operator">,</span> <span class="String">'&amp;Quit\tCtrl+Q'</span><span class="Operator">,</span> <span class="String">'Quit the Application'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  19 </span>        <span class="ID">quit</span><span class="Operator">.</span><span class="ID">SetBitmap</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Image</span><span class="Operator">(</span><span class="String">'stock_exit-16.png'</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BITMAP_TYPE_PNG</span><span class="Operator">)</span><span class="Operator">.</span><span class="ID">ConvertToBitmap</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  20 </span>        <span class="ID">file</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">quit</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  21 </span></span>
<span class="line"><span class="LineNumber">  22 </span>        <span class="ID">menubar</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="ID">file</span><span class="Operator">,</span> <span class="String">'&amp;File'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  23 </span>        <span class="ID">menubar</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="ID">edit</span><span class="Operator">,</span> <span class="String">'&amp;Edit'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  24 </span>        <span class="ID">menubar</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="ID">help</span><span class="Operator">,</span> <span class="String">'&amp;Help'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  25 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetMenuBar</span><span class="Operator">(</span><span class="ID">menubar</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  26 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">CreateStatusBar</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  27 </span></span>
<span class="line"><span class="LineNumber">  28 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  29 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  30 </span>        <span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">MyMenu</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'menu1.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  31 </span>        <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  32 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  33 </span></span>
<span class="line"><span class="LineNumber">  34 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  35 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-311"></span><p class="line874">So
 far we have seen the default, normal menu items. Here we see, how we 
can explicitly define check items, normal items or radio items. <span class="anchor" id="line-312"></span><span class="anchor" id="line-313"></span></p><p class="line867"><span class="anchor" id="line-314"></span><span class="anchor" id="line-315"></span><span class="anchor" id="line-316"></span></p><pre>edit.Append(201, 'check item1', '', wx.ITEM_CHECK)
edit.Append(202, 'check item2', '', kind=wx.ITEM_CHECK)</pre><span class="anchor" id="line-317"></span><p class="line874">or <span class="anchor" id="line-318"></span><span class="anchor" id="line-319"></span></p><p class="line867"><span class="anchor" id="line-320"></span><span class="anchor" id="line-321"></span></p><pre>quit = wxMenuItem(file, 105, '&amp;Quit\tCtrl+Q', 'Quit the Application', wx.ITEM_NORMAL)</pre><span class="anchor" id="line-322"></span><p class="line874">The parameter is called kind. <span class="anchor" id="line-323"></span><span class="anchor" id="line-324"></span></p><p class="line862">Possible <tt>wx.ItemKind</tt>-s <span class="anchor" id="line-325"></span><span class="anchor" id="line-326"></span></p><ul><li>wx.ITEM_NORMAL - default item <span class="anchor" id="line-327"></span></li><li>wx.ITEM_CHECK - check item <span class="anchor" id="line-328"></span></li><li>wx.ITEM_RADIO - radio item <span class="anchor" id="line-329"></span><span class="anchor" id="line-330"></span></li></ul><p class="line874">If you want to create a submenu, you create a menu first. <span class="anchor" id="line-331"></span><span class="anchor" id="line-332"></span></p><p class="line867"><span class="anchor" id="line-333"></span><span class="anchor" id="line-334"></span></p><pre>submenu = wx.Menu()</pre><span class="anchor" id="line-335"></span><p class="line874">Then append some menu items into this submenu. <span class="anchor" id="line-336"></span><span class="anchor" id="line-337"></span></p><p class="line867"><span class="anchor" id="line-338"></span><span class="anchor" id="line-339"></span><span class="anchor" id="line-340"></span><span class="anchor" id="line-341"></span></p><pre>submenu.Append(301, 'radio item1', kind=wx.ITEM_RADIO)
submenu.Append(302, 'radio item2', kind=wx.ITEM_RADIO)
submenu.Append(302, 'radio item3', kind=wx.ITEM_RADIO)</pre><span class="anchor" id="line-342"></span><p class="line874">You finish with adding a submenu into a menu object. <span class="anchor" id="line-343"></span><span class="anchor" id="line-344"></span></p><p class="line867"><span class="anchor" id="line-345"></span><span class="anchor" id="line-346"></span></p><pre>edit.AppendMenu(203, 'submenu', submenu)</pre><span class="anchor" id="line-347"></span><p class="line874">We now discuss how to respond to user actions. We will touch on it only briefly and explain it later in more detail. <span class="anchor" id="line-348"></span><span class="anchor" id="line-349"></span></p><p class="line874">So
 when a user of our application selects a menu item, an event is 
generated. We must provide an event handler, that will react to this 
event accordingly. Handling events in wxPython is the most elegant and 
simple that I have seen so far. When we look into the reference book, we
 find wx.EVT_MENU handler under Event handling section. <span class="anchor" id="line-350"></span><span class="anchor" id="line-351"></span></p><p class="line874">Suppose we want to add an event handler to our quit menu item. <span class="anchor" id="line-352"></span><span class="anchor" id="line-353"></span></p><p class="line867"><span class="anchor" id="line-354"></span><span class="anchor" id="line-355"></span></p><pre>wx.EVT_MENU(self, 105, self.OnQuit )</pre><span class="anchor" id="line-356"></span><p class="line874">We
 need to provide three pieces of information. The object, where we bind 
our event handler. In our case self, the application's main object. The 
id of the corresponding menu item. And the method name, which will do 
our job. <span class="anchor" id="line-357"></span><span class="anchor" id="line-358"></span></p><p class="line874">The
 method which will react to user actions has two parameters. The first 
one is the object where this method is defined. The second one is the 
generated event. This time, we do without it. We simply close our 
application. <span class="anchor" id="line-359"></span><span class="anchor" id="line-360"></span></p><p class="line867"><span class="anchor" id="line-361"></span><span class="anchor" id="line-362"></span><span class="anchor" id="line-363"></span></p><pre>def OnQuit(self, event):
    self.Close()</pre><span class="anchor" id="line-364"></span><p class="line874">The
 following script demonstrates various menu items, submenu and one 
simple event handler. I hate when my application window pops up 
somewhere in the corner by the will of the allmighty window manager. So I
 added <span class="anchor" id="line-365"></span><span class="anchor" id="line-366"></span></p><p class="line867"><span class="anchor" id="line-367"></span><span class="anchor" id="line-368"></span></p><pre>self.Centre()</pre><span class="anchor" id="line-369"></span><p class="line874">so that the window pops up in the center of the screen. <span class="anchor" id="line-370"></span><span class="anchor" id="line-371"></span></p><p class="line867"><img alt="menu1.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_036.png" title="menu1.png"> <span class="anchor" id="line-372"></span><span class="anchor" id="line-373"></span></p><p class="line867"><strong>Figure: menu1.py</strong> <span class="anchor" id="line-374"></span><span class="anchor" id="line-375"></span></p><p class="line867"><span class="anchor" id="line-376"></span><span class="anchor" id="line-377"></span><span class="anchor" id="line-378"></span><span class="anchor" id="line-379"></span><span class="anchor" id="line-380"></span><span class="anchor" id="line-381"></span><span class="anchor" id="line-382"></span><span class="anchor" id="line-383"></span><span class="anchor" id="line-384"></span><span class="anchor" id="line-385"></span><span class="anchor" id="line-386"></span><span class="anchor" id="line-387"></span><span class="anchor" id="line-388"></span><span class="anchor" id="line-389"></span><span class="anchor" id="line-390"></span><span class="anchor" id="line-391"></span><span class="anchor" id="line-392"></span><span class="anchor" id="line-393"></span><span class="anchor" id="line-394"></span><span class="anchor" id="line-395"></span><span class="anchor" id="line-396"></span><span class="anchor" id="line-397"></span><span class="anchor" id="line-398"></span><span class="anchor" id="line-399"></span><span class="anchor" id="line-400"></span><span class="anchor" id="line-401"></span><span class="anchor" id="line-402"></span><span class="anchor" id="line-403"></span><span class="anchor" id="line-404"></span><span class="anchor" id="line-405"></span><span class="anchor" id="line-406"></span><span class="anchor" id="line-407"></span><span class="anchor" id="line-408"></span><span class="anchor" id="line-409"></span><span class="anchor" id="line-410"></span><span class="anchor" id="line-411"></span><span class="anchor" id="line-412"></span><span class="anchor" id="line-413"></span><span class="anchor" id="line-414"></span><span class="anchor" id="line-415"></span><span class="anchor" id="line-416"></span><span class="anchor" id="line-417"></span><span class="anchor" id="line-418"></span><span class="anchor" id="line-419"></span><span class="anchor" id="line-420"></span><span class="anchor" id="line-421"></span><span class="anchor" id="line-422"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-5f6d57059811103129c24b9b6991ef498b8bc076\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-5f6d57059811103129c24b9b6991ef498b8bc076', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-5f6d57059811103129c24b9b6991ef498b8bc076" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># menu2.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ResWord">class</span> <span class="ID">MyMenu</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   8 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">DefaultPosition</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Size</span><span class="Operator">(</span><span class="Number">380</span><span class="Operator">,</span> <span class="Number">250</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  10 </span></span>
<span class="line"><span class="LineNumber">  11 </span>        <span class="ID">menubar</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MenuBar</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">file</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Menu</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">edit</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Menu</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">help</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Menu</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">file</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="Number">101</span><span class="Operator">,</span> <span class="String">'&amp;Open'</span><span class="Operator">,</span> <span class="String">'Open a new document'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span>        <span class="ID">file</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="Number">102</span><span class="Operator">,</span> <span class="String">'&amp;Save'</span><span class="Operator">,</span> <span class="String">'Save the document'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="ID">file</span><span class="Operator">.</span><span class="ID">AppendSeparator</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  18 </span>        <span class="ID">quit</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MenuItem</span><span class="Operator">(</span><span class="ID">file</span><span class="Operator">,</span> <span class="Number">105</span><span class="Operator">,</span> <span class="String">'&amp;Quit\tCtrl+Q'</span><span class="Operator">,</span> <span class="String">'Quit the Application'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  19 </span>        <span class="ID">quit</span><span class="Operator">.</span><span class="ID">SetBitmap</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Image</span><span class="Operator">(</span><span class="String">'stock_exit-16.png'</span><span class="Operator">,</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">BITMAP_TYPE_PNG</span><span class="Operator">)</span><span class="Operator">.</span><span class="ID">ConvertToBitmap</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  20 </span>        <span class="ID">file</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">quit</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  21 </span>        <span class="ID">edit</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="Number">201</span><span class="Operator">,</span> <span class="String">'check item1'</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ITEM_CHECK</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  22 </span>        <span class="ID">edit</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="Number">202</span><span class="Operator">,</span> <span class="String">'check item2'</span><span class="Operator">,</span> <span class="ID">kind</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">ITEM_CHECK</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  23 </span>        <span class="ID">submenu</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Menu</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  24 </span>        <span class="ID">submenu</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="Number">301</span><span class="Operator">,</span> <span class="String">'radio item1'</span><span class="Operator">,</span> <span class="ID">kind</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">ITEM_RADIO</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  25 </span>        <span class="ID">submenu</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="Number">302</span><span class="Operator">,</span> <span class="String">'radio item2'</span><span class="Operator">,</span> <span class="ID">kind</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">ITEM_RADIO</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  26 </span>        <span class="ID">submenu</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="Number">303</span><span class="Operator">,</span> <span class="String">'radio item3'</span><span class="Operator">,</span> <span class="ID">kind</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">ITEM_RADIO</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  27 </span>        <span class="ID">edit</span><span class="Operator">.</span><span class="ID">AppendMenu</span><span class="Operator">(</span><span class="Number">203</span><span class="Operator">,</span> <span class="String">'submenu'</span><span class="Operator">,</span> <span class="ID">submenu</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  28 </span>        <span class="ID">menubar</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="ID">file</span><span class="Operator">,</span> <span class="String">'&amp;File'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  29 </span>        <span class="ID">menubar</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="ID">edit</span><span class="Operator">,</span> <span class="String">'&amp;Edit'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  30 </span>        <span class="ID">menubar</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="ID">help</span><span class="Operator">,</span> <span class="String">'&amp;Help'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  31 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetMenuBar</span><span class="Operator">(</span><span class="ID">menubar</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  32 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  33 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_MENU</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnQuit</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">105</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  34 </span></span>
<span class="line"><span class="LineNumber">  35 </span>    <span class="ResWord">def</span> <span class="ID">OnQuit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  36 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Close</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  37 </span></span>
<span class="line"><span class="LineNumber">  38 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  39 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  40 </span>        <span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">MyMenu</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'menu2.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  41 </span>        <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  42 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  43 </span></span>
<span class="line"><span class="LineNumber">  44 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  45 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-423"></span><p class="line867"><img alt="menu2.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_006.png" title="menu2.png"> <span class="anchor" id="line-424"></span><span class="anchor" id="line-425"></span></p><p class="line867"><strong>Figure: menu2.py</strong> <span class="anchor" id="line-426"></span><span class="anchor" id="line-427"></span></p><p class="line867">
</p><h3 id="wx.ToolBar">wx.ToolBar</h3>
<span class="anchor" id="line-428"></span><p class="line874">Toolbar is a
 widget that groups the most common used commands or actions of your 
application. Typically save, open, cut, copy, paste, undo, redo etc. 
It's purpose is to save time. You need one click to do an action from 
the toolbar and two clicks from the menu. <span class="anchor" id="line-429"></span><span class="anchor" id="line-430"></span></p><p class="line867"><span class="anchor" id="line-431"></span><span class="anchor" id="line-432"></span><span class="anchor" id="line-433"></span><span class="anchor" id="line-434"></span><span class="anchor" id="line-435"></span><span class="anchor" id="line-436"></span><span class="anchor" id="line-437"></span><span class="anchor" id="line-438"></span><span class="anchor" id="line-439"></span><span class="anchor" id="line-440"></span><span class="anchor" id="line-441"></span><span class="anchor" id="line-442"></span><span class="anchor" id="line-443"></span><span class="anchor" id="line-444"></span><span class="anchor" id="line-445"></span><span class="anchor" id="line-446"></span><span class="anchor" id="line-447"></span><span class="anchor" id="line-448"></span><span class="anchor" id="line-449"></span><span class="anchor" id="line-450"></span><span class="anchor" id="line-451"></span><span class="anchor" id="line-452"></span><span class="anchor" id="line-453"></span><span class="anchor" id="line-454"></span><span class="anchor" id="line-455"></span><span class="anchor" id="line-456"></span><span class="anchor" id="line-457"></span><span class="anchor" id="line-458"></span><span class="anchor" id="line-459"></span><span class="anchor" id="line-460"></span><span class="anchor" id="line-461"></span><span class="anchor" id="line-462"></span><span class="anchor" id="line-463"></span><span class="anchor" id="line-464"></span><span class="anchor" id="line-465"></span><span class="anchor" id="line-466"></span><span class="anchor" id="line-467"></span><span class="anchor" id="line-468"></span><span class="anchor" id="line-469"></span><span class="anchor" id="line-470"></span><span class="anchor" id="line-471"></span><span class="anchor" id="line-472"></span><span class="anchor" id="line-473"></span><span class="anchor" id="line-474"></span><span class="anchor" id="line-475"></span><span class="anchor" id="line-476"></span><span class="anchor" id="line-477"></span><span class="anchor" id="line-478"></span><span class="anchor" id="line-479"></span><span class="anchor" id="line-480"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-7546a3b506316206b28f8dac05c9d228ab4804c3\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-7546a3b506316206b28f8dac05c9d228ab4804c3', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-7546a3b506316206b28f8dac05c9d228ab4804c3" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># toolbar.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ResWord">class</span> <span class="ID">MyToolBar</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   8 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">DefaultPosition</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Size</span><span class="Operator">(</span><span class="Number">350</span><span class="Operator">,</span> <span class="Number">250</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  10 </span></span>
<span class="line"><span class="LineNumber">  11 </span>        <span class="ID">vbox</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BoxSizer</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">VERTICAL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">toolbar</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ToolBar</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">TB_HORIZONTAL</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">NO_BORDER</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">toolbar</span><span class="Operator">.</span><span class="ID">AddSimpleTool</span><span class="Operator">(</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Image</span><span class="Operator">(</span><span class="String">'stock_new.png'</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BITMAP_TYPE_PNG</span><span class="Operator">)</span><span class="Operator">.</span><span class="ID">ConvertToBitmap</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">,</span> <span class="String">'New'</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">toolbar</span><span class="Operator">.</span><span class="ID">AddSimpleTool</span><span class="Operator">(</span><span class="Number">2</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Image</span><span class="Operator">(</span><span class="String">'stock_open.png'</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BITMAP_TYPE_PNG</span><span class="Operator">)</span><span class="Operator">.</span><span class="ID">ConvertToBitmap</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">,</span> <span class="String">'Open'</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">toolbar</span><span class="Operator">.</span><span class="ID">AddSimpleTool</span><span class="Operator">(</span><span class="Number">3</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Image</span><span class="Operator">(</span><span class="String">'stock_save.png'</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BITMAP_TYPE_PNG</span><span class="Operator">)</span><span class="Operator">.</span><span class="ID">ConvertToBitmap</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">,</span> <span class="String">'Save'</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span>        <span class="ID">toolbar</span><span class="Operator">.</span><span class="ID">AddSeparator</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="ID">toolbar</span><span class="Operator">.</span><span class="ID">AddSimpleTool</span><span class="Operator">(</span><span class="Number">4</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Image</span><span class="Operator">(</span><span class="String">'stock_exit.png'</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BITMAP_TYPE_PNG</span><span class="Operator">)</span><span class="Operator">.</span><span class="ID">ConvertToBitmap</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">,</span> <span class="String">'Exit'</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  18 </span>        <span class="ID">toolbar</span><span class="Operator">.</span><span class="ID">Realize</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  19 </span>        <span class="ID">vbox</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">toolbar</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">border</span><span class="Operator">=</span><span class="Number">5</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  20 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetSizer</span><span class="Operator">(</span><span class="ID">vbox</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  21 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">statusbar</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">CreateStatusBar</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  22 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  23 </span></span>
<span class="line"><span class="LineNumber">  24 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_TOOL</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnNew</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  25 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_TOOL</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnOpen</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">2</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  26 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_TOOL</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnSave</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">3</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  27 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_TOOL</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnExit</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">4</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  28 </span></span>
<span class="line"><span class="LineNumber">  29 </span>    <span class="ResWord">def</span> <span class="ID">OnNew</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  30 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">statusbar</span><span class="Operator">.</span><span class="ID">SetStatusText</span><span class="Operator">(</span><span class="String">'New Command'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  31 </span></span>
<span class="line"><span class="LineNumber">  32 </span>    <span class="ResWord">def</span> <span class="ID">OnOpen</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  33 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">statusbar</span><span class="Operator">.</span><span class="ID">SetStatusText</span><span class="Operator">(</span><span class="String">'Open Command'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  34 </span></span>
<span class="line"><span class="LineNumber">  35 </span>    <span class="ResWord">def</span> <span class="ID">OnSave</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  36 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">statusbar</span><span class="Operator">.</span><span class="ID">SetStatusText</span><span class="Operator">(</span><span class="String">'Save Command'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  37 </span></span>
<span class="line"><span class="LineNumber">  38 </span>    <span class="ResWord">def</span> <span class="ID">OnExit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  39 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Close</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  40 </span></span>
<span class="line"><span class="LineNumber">  41 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  42 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  43 </span>        <span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">MyToolBar</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'toolbar.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  44 </span>        <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  45 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  46 </span></span>
<span class="line"><span class="LineNumber">  47 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  48 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-481"></span><p class="line867"><tt>wx.BoxSizer</tt> will be explained later in layout section. Toolbar widget is created in three steps. <span class="anchor" id="line-482"></span><span class="anchor" id="line-483"></span></p><p class="line874">Firstly, we create a toolbar object. <span class="anchor" id="line-484"></span><span class="anchor" id="line-485"></span></p><p class="line867"><span class="anchor" id="line-486"></span><span class="anchor" id="line-487"></span></p><pre>toolbar = wx.ToolBar(self, -1, style=wx.TB_HORIZONTAL | wx.NO_BORDER)</pre><span class="anchor" id="line-488"></span><p class="line862">Then we add some tools to the toolbar with the <tt>AddSimpleTool()</tt>
 method. You don't find this method in the reference book. It is a 
wxPython 'extension'.  This is a curse and also a blessing. It makes 
python programming easier. But on the other hand, these extensions are 
undocumented. You have to look at the wrapper code, demo example or ask 
on the mailing list. <span class="anchor" id="line-489"></span><span class="anchor" id="line-490"></span></p><p class="line867"><span class="anchor" id="line-491"></span><span class="anchor" id="line-492"></span></p><pre>toolbar.AddSimpleTool(1, wx.Image('stock_new.png',  wx.BITMAP_TYPE_PNG).ConvertToBitmap(), 'New', '')</pre><span class="anchor" id="line-493"></span><p class="line862">In the end, we call the <tt>Realize()</tt> method. This method shows or renders the toolbar widget. <span class="anchor" id="line-494"></span><span class="anchor" id="line-495"></span></p><p class="line867"><span class="anchor" id="line-496"></span><span class="anchor" id="line-497"></span></p><pre>toolbar.Realize()</pre><span class="anchor" id="line-498"></span><p class="line874">The
 toolbar widget has several event handlers. When you click on a toolbar 
icon a wx.EVT_COMMAND_TOOL_CLICKED event is generated. We bind this 
event to a specified method with the wx.EVT_TOOL handler. <span class="anchor" id="line-499"></span><span class="anchor" id="line-500"></span></p><p class="line874">In order to show some meaningful output to our events, we have set up a statusbar. <span class="anchor" id="line-501"></span><span class="anchor" id="line-502"></span></p><p class="line867"><span class="anchor" id="line-503"></span><span class="anchor" id="line-504"></span></p><pre>self.statusbar = self.CreateStatusBar()</pre><span class="anchor" id="line-505"></span><p class="line862">This
 is yet another wxPython extension. So when we click on a toolbar 
button, a message is displayed on the statusbar. This is done with the <tt>SetStatusText()</tt> method. <span class="anchor" id="line-506"></span><span class="anchor" id="line-507"></span></p><p class="line867"><img alt="toolbar.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_054.png" title="toolbar.png"> <span class="anchor" id="line-508"></span><span class="anchor" id="line-509"></span></p><p class="line867"><strong>Figure: toolbar.py</strong> <span class="anchor" id="line-510"></span><span class="anchor" id="line-511"></span></p><p class="line867">
</p><h2 id="Layout__Management">Layout  Management</h2>
<span class="anchor" id="line-512"></span><p class="line874">There are 
basically two methods for layout of our widgets. The first method is 
manual. We place widgets by specifying the position in the constructor 
of the widget. <span class="anchor" id="line-513"></span><span class="anchor" id="line-514"></span></p><p class="line867"><span class="anchor" id="line-515"></span><span class="anchor" id="line-516"></span><span class="anchor" id="line-517"></span><span class="anchor" id="line-518"></span><span class="anchor" id="line-519"></span><span class="anchor" id="line-520"></span><span class="anchor" id="line-521"></span><span class="anchor" id="line-522"></span><span class="anchor" id="line-523"></span><span class="anchor" id="line-524"></span><span class="anchor" id="line-525"></span><span class="anchor" id="line-526"></span><span class="anchor" id="line-527"></span><span class="anchor" id="line-528"></span><span class="anchor" id="line-529"></span><span class="anchor" id="line-530"></span><span class="anchor" id="line-531"></span><span class="anchor" id="line-532"></span><span class="anchor" id="line-533"></span><span class="anchor" id="line-534"></span><span class="anchor" id="line-535"></span><span class="anchor" id="line-536"></span><span class="anchor" id="line-537"></span><span class="anchor" id="line-538"></span><span class="anchor" id="line-539"></span><span class="anchor" id="line-540"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-8fa049642856a927f7d412250039c92d9be4d89f\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-8fa049642856a927f7d412250039c92d9be4d89f', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-8fa049642856a927f7d412250039c92d9be4d89f" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># layout.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ResWord">class</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   8 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">DefaultPosition</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Size</span><span class="Operator">(</span><span class="Number">250</span><span class="Operator">,</span> <span class="Number">50</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  10 </span></span>
<span class="line"><span class="LineNumber">  11 </span>        <span class="ID">panel</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">"Button1"</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">0</span><span class="Operator">,</span><span class="Number">0</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">"Button2"</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">80</span><span class="Operator">,</span><span class="Number">0</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">"Button3"</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">160</span><span class="Operator">,</span><span class="Number">0</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span></span>
<span class="line"><span class="LineNumber">  16 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  17 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  18 </span>        <span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'layout.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  19 </span>        <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  20 </span>        <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  21 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  22 </span></span>
<span class="line"><span class="LineNumber">  23 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  24 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-541"></span><p class="line874">When
 the window is resized, the size and the position of buttons do not 
change. This is one of the main features of the manual positioning of 
the widgets. <span class="anchor" id="line-542"></span><span class="anchor" id="line-543"></span></p><p class="line867"><img alt="layout.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_011.png" title="layout.png"> <span class="anchor" id="line-544"></span><span class="anchor" id="line-545"></span></p><p class="line867"><strong>Figure: layout.py</strong> <span class="anchor" id="line-546"></span><span class="anchor" id="line-547"></span></p><p class="line874">The
 second method is to use layout managers. This method is prevalent in 
real programs. Basically you use sizers. We will discuss <span class="anchor" id="line-548"></span><span class="anchor" id="line-549"></span></p><ul><li><p class="line891"><tt>wx.BoxSizer</tt> <span class="anchor" id="line-550"></span></p></li><li><p class="line891"><tt>wx.StaticBoxSizer</tt> <span class="anchor" id="line-551"></span></p></li><li><p class="line891"><tt>wx.GridSizer</tt> <span class="anchor" id="line-552"></span></p></li><li><p class="line891"><tt>wx.GridBagSizer</tt> <span class="anchor" id="line-553"></span><span class="anchor" id="line-554"></span></p></li></ul><p class="line867">
</p><h3 id="wx.BoxSizer">wx.BoxSizer</h3>
<span class="anchor" id="line-555"></span><p class="line874">Let's make a
 program in which three buttons will occupy one row placed at the top of
 the window. These buttons will resize when the window is resized. <span class="anchor" id="line-556"></span><span class="anchor" id="line-557"></span></p><p class="line867"><span class="anchor" id="line-558"></span><span class="anchor" id="line-559"></span><span class="anchor" id="line-560"></span><span class="anchor" id="line-561"></span><span class="anchor" id="line-562"></span><span class="anchor" id="line-563"></span><span class="anchor" id="line-564"></span><span class="anchor" id="line-565"></span><span class="anchor" id="line-566"></span><span class="anchor" id="line-567"></span><span class="anchor" id="line-568"></span><span class="anchor" id="line-569"></span><span class="anchor" id="line-570"></span><span class="anchor" id="line-571"></span><span class="anchor" id="line-572"></span><span class="anchor" id="line-573"></span><span class="anchor" id="line-574"></span><span class="anchor" id="line-575"></span><span class="anchor" id="line-576"></span><span class="anchor" id="line-577"></span><span class="anchor" id="line-578"></span><span class="anchor" id="line-579"></span><span class="anchor" id="line-580"></span><span class="anchor" id="line-581"></span><span class="anchor" id="line-582"></span><span class="anchor" id="line-583"></span><span class="anchor" id="line-584"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-5320812772aad7609e70f920864c98ace30ac34b\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-5320812772aad7609e70f920864c98ace30ac34b', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-5320812772aad7609e70f920864c98ace30ac34b" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># wxboxsizer.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ResWord">class</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   8 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Size</span><span class="Operator">(</span><span class="Number">250</span><span class="Operator">,</span> <span class="Number">50</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  10 </span>        <span class="ID">panel</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  11 </span>        <span class="ID">box</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BoxSizer</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">HORIZONTAL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">box</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Button1'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Number">1</span> <span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">box</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Button2'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Number">1</span> <span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">box</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Button3'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Number">1</span> <span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">panel</span><span class="Operator">.</span><span class="ID">SetSizer</span><span class="Operator">(</span><span class="ID">box</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span></span>
<span class="line"><span class="LineNumber">  18 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  19 </span>     <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  20 </span>         <span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'wxboxsizer.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  21 </span>         <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  22 </span>         <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  23 </span></span>
<span class="line"><span class="LineNumber">  24 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  25 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-585"></span><p class="line874">We can place widgets vertically or horizontally. <span class="anchor" id="line-586"></span><span class="anchor" id="line-587"></span></p><p class="line867"><span class="anchor" id="line-588"></span><span class="anchor" id="line-589"></span></p><pre>box = wx.BoxSizer(integer orient)</pre><span class="anchor" id="line-590"></span><p class="line862">where orientation can be <tt>wx.VERTICAL</tt> or <tt>wx.HORIZONTAL</tt>. Adding widgets into the <tt>wx.BoxSizer</tt> is done via the <tt>Add()</tt> method. In order to understand it, we need to look at its parameters. <span class="anchor" id="line-591"></span><span class="anchor" id="line-592"></span></p><p class="line867"><span class="anchor" id="line-593"></span><span class="anchor" id="line-594"></span></p><pre>Add(wx.Window window, integer proportion=0, integer flag = 0, integer border = 0)</pre><span class="anchor" id="line-595"></span><p class="line867"><img alt="wxboxsizer.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_010.png" title="wxboxsizer.png"> <span class="anchor" id="line-596"></span><span class="anchor" id="line-597"></span></p><p class="line867"><strong>Figure: wxboxsizer.py</strong> <span class="anchor" id="line-598"></span><span class="anchor" id="line-599"></span></p><p class="line862">The
 proportion parameter defines the share or ratio of available sizer 
space that the widget will occupy in the direction of the defined 
orientation. Let's assume we have three buttons with the proportions 0, 
1, and 2. They are added into a horizontal <tt>wx.BoxSizer</tt>. The 
button with proportion 0 will not change at all when the sizer's width 
(horizontal size) changes (i.e. the button will always be the same 
width). The rest of the width of the sizer is split into 3 (2+1) shares.
  The button with proportion 2 will always occupy 2 of those 3 shares 
(its width will be 2/3 of the available width), and the button with 
proportion 1 will always occupy 1 of those shares. <span class="anchor" id="line-600"></span><span class="anchor" id="line-601"></span></p><p class="line862">With the flag parameter, you can further configure the behaviour of the widgets within a <tt>wx.BoxSizer</tt>.
 We can control the border (though "padding" would be a more accurate 
name than "border") between the widgets. We add some space between 
widgets in pixels.  In order to apply border, we need to define which 
sides will use the border.  We can choose between these flags: <span class="anchor" id="line-602"></span><span class="anchor" id="line-603"></span></p><ul><li>wx.LEFT <span class="anchor" id="line-604"></span></li><li>wx.RIGHT <span class="anchor" id="line-605"></span></li><li>wx.BOTTOM <span class="anchor" id="line-606"></span></li><li>wx.TOP <span class="anchor" id="line-607"></span></li><li>wx.ALL <span class="anchor" id="line-608"></span><span class="anchor" id="line-609"></span></li></ul><p class="line862">We can combine them with the | operator. e.g <tt>wx.LEFT</tt> | <tt>wx.BOTTOM</tt>. If we use <tt>wx.EXPAND</tt>
 flag, our widget will use all the space that is available in the 
direction perpendicular to the sizer's orient direction. Lastly, we can 
also define the alignment of our widgets. We do it with the following 
flags : <span class="anchor" id="line-610"></span><span class="anchor" id="line-611"></span></p><ul><li>wx.ALIGN_LEFT <span class="anchor" id="line-612"></span></li><li>wx.ALIGN_RIGHT <span class="anchor" id="line-613"></span></li><li>wx.ALIGN_TOP <span class="anchor" id="line-614"></span></li><li>wx.ALIGN_BOTTOM <span class="anchor" id="line-615"></span></li><li>wx.ALIGN_CENTER_VERTICAL <span class="anchor" id="line-616"></span></li><li>wx.ALIGN_CENTER_HORIZONTAL <span class="anchor" id="line-617"></span></li><li>wx.ALIGN_CENTER <span class="anchor" id="line-618"></span><span class="anchor" id="line-619"></span></li></ul><p class="line874">An example: <span class="anchor" id="line-620"></span><span class="anchor" id="line-621"></span></p><p class="line867"><span class="anchor" id="line-622"></span><span class="anchor" id="line-623"></span><span class="anchor" id="line-624"></span><span class="anchor" id="line-625"></span><span class="anchor" id="line-626"></span><span class="anchor" id="line-627"></span><span class="anchor" id="line-628"></span><span class="anchor" id="line-629"></span><span class="anchor" id="line-630"></span><span class="anchor" id="line-631"></span><span class="anchor" id="line-632"></span><span class="anchor" id="line-633"></span><span class="anchor" id="line-634"></span><span class="anchor" id="line-635"></span><span class="anchor" id="line-636"></span><span class="anchor" id="line-637"></span><span class="anchor" id="line-638"></span><span class="anchor" id="line-639"></span><span class="anchor" id="line-640"></span><span class="anchor" id="line-641"></span><span class="anchor" id="line-642"></span><span class="anchor" id="line-643"></span><span class="anchor" id="line-644"></span><span class="anchor" id="line-645"></span><span class="anchor" id="line-646"></span><span class="anchor" id="line-647"></span><span class="anchor" id="line-648"></span><span class="anchor" id="line-649"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-a94d31c7470c9894c0164cf63d2e2dc01e4af958\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-a94d31c7470c9894c0164cf63d2e2dc01e4af958', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-a94d31c7470c9894c0164cf63d2e2dc01e4af958" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># layout3.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ResWord">class</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   8 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Size</span><span class="Operator">(</span><span class="Number">450</span><span class="Operator">,</span> <span class="Number">300</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  10 </span></span>
<span class="line"><span class="LineNumber">  11 </span>        <span class="ID">panel</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">box</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BoxSizer</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">HORIZONTAL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">box</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Button1'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALL</span><span class="Operator">,</span> <span class="Number">5</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">box</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Button2'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">box</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Button3'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_CENTER</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span>        <span class="ID">panel</span><span class="Operator">.</span><span class="ID">SetSizer</span><span class="Operator">(</span><span class="ID">box</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  18 </span></span>
<span class="line"><span class="LineNumber">  19 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  20 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  21 </span>        <span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'layout3.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  22 </span>        <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  23 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  24 </span></span>
<span class="line"><span class="LineNumber">  25 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  26 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-650"></span><p class="line874">In
 our example we again have three buttons. The first one has some border 
around all its sides. It is the only one that changes in the horizontal 
dimension when the main window is resized. The second one occupies all 
space alloted to it in the vertical direction. The third one is aligned 
in the centre. <span class="anchor" id="line-651"></span><span class="anchor" id="line-652"></span></p><p class="line862">We can combine various <tt>wx.BoxSizer-s</tt>. For example, we can put several horizontal <tt>wx.BoxSizer-s</tt> into a vertical <tt>wx.BoxSizer</tt> and vice versa. This way we can make complex layouts. <span class="anchor" id="line-653"></span><span class="anchor" id="line-654"></span></p><p class="line867"><span class="anchor" id="line-655"></span><span class="anchor" id="line-656"></span><span class="anchor" id="line-657"></span><span class="anchor" id="line-658"></span><span class="anchor" id="line-659"></span><span class="anchor" id="line-660"></span><span class="anchor" id="line-661"></span><span class="anchor" id="line-662"></span><span class="anchor" id="line-663"></span><span class="anchor" id="line-664"></span><span class="anchor" id="line-665"></span><span class="anchor" id="line-666"></span><span class="anchor" id="line-667"></span><span class="anchor" id="line-668"></span><span class="anchor" id="line-669"></span><span class="anchor" id="line-670"></span><span class="anchor" id="line-671"></span><span class="anchor" id="line-672"></span><span class="anchor" id="line-673"></span><span class="anchor" id="line-674"></span><span class="anchor" id="line-675"></span><span class="anchor" id="line-676"></span><span class="anchor" id="line-677"></span><span class="anchor" id="line-678"></span><span class="anchor" id="line-679"></span><span class="anchor" id="line-680"></span><span class="anchor" id="line-681"></span><span class="anchor" id="line-682"></span><span class="anchor" id="line-683"></span><span class="anchor" id="line-684"></span><span class="anchor" id="line-685"></span><span class="anchor" id="line-686"></span><span class="anchor" id="line-687"></span><span class="anchor" id="line-688"></span><span class="anchor" id="line-689"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-496630cba17607fe4945a97fa172807715cc523b\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-496630cba17607fe4945a97fa172807715cc523b', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-496630cba17607fe4945a97fa172807715cc523b" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># borders.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ResWord">class</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   8 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span></span>
<span class="line"><span class="LineNumber">  10 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  11 </span>        <span class="ID">hbox</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BoxSizer</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">HORIZONTAL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">pnl1</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">SIMPLE_BORDER</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">pnl2</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">RAISED_BORDER</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">pnl3</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">SUNKEN_BORDER</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">pnl4</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">NO_BORDER</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="ID">hbox</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">pnl1</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALL</span><span class="Operator">,</span> <span class="Number">3</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  18 </span>        <span class="ID">hbox</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">pnl2</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALL</span><span class="Operator">,</span> <span class="Number">3</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  19 </span>        <span class="ID">hbox</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">pnl3</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALL</span><span class="Operator">,</span> <span class="Number">3</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  20 </span>        <span class="ID">hbox</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">pnl4</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALL</span><span class="Operator">,</span> <span class="Number">3</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  21 </span></span>
<span class="line"><span class="LineNumber">  22 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetSize</span><span class="Operator">(</span><span class="Operator">(</span><span class="Number">400</span><span class="Operator">,</span> <span class="Number">120</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  23 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetSizer</span><span class="Operator">(</span><span class="ID">hbox</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  24 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  25 </span></span>
<span class="line"><span class="LineNumber">  26 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  27 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  28 </span>        <span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'borders.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  29 </span>        <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  30 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  31 </span></span>
<span class="line"><span class="LineNumber">  32 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  33 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-690"></span><p class="line874">We show four various border styles available in wxPython. Border is a simple window decoration. <span class="anchor" id="line-691"></span><span class="anchor" id="line-692"></span></p><p class="line874">Available Borders: <span class="anchor" id="line-693"></span><span class="anchor" id="line-694"></span></p><ul><li>wx.SIMPLE_BORDER <span class="anchor" id="line-695"></span></li><li>wx.RAISED_BORDER <span class="anchor" id="line-696"></span></li><li>wx.SUNKEN_BORDER <span class="anchor" id="line-697"></span></li><li>wx.NO_BORDER <span class="anchor" id="line-698"></span><span class="anchor" id="line-699"></span></li></ul><p class="line867"><img alt="borders.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_040.png" title="borders.png"> <span class="anchor" id="line-700"></span><span class="anchor" id="line-701"></span></p><p class="line867">
</p><h3 id="wx.GridSizer">wx.GridSizer</h3>
<span class="anchor" id="line-702"></span><p class="line867"><tt>wx.GridSizer</tt>
 lays out its children in a two-dimensional table. The width of each 
field is the width of the widest child. The height of each field is the 
height of the tallest child. <span class="anchor" id="line-703"></span><span class="anchor" id="line-704"></span></p><p class="line867"><span class="anchor" id="line-705"></span><span class="anchor" id="line-706"></span></p><pre>wx.GridSizer(integer rows, integer cols, integer vgap, integer hgap)</pre><span class="anchor" id="line-707"></span><p class="line862">In
 the constructor we provide the number of rows and  the number of 
columns of our table and the horizontal and vertical gap between the 
children widgets. We insert our widgets into the table with the <tt>AddMany()</tt> method. Children are inserted from left to right, top to bottom. <span class="anchor" id="line-708"></span><span class="anchor" id="line-709"></span></p><p class="line867"><span class="anchor" id="line-710"></span><span class="anchor" id="line-711"></span><span class="anchor" id="line-712"></span><span class="anchor" id="line-713"></span><span class="anchor" id="line-714"></span><span class="anchor" id="line-715"></span><span class="anchor" id="line-716"></span><span class="anchor" id="line-717"></span><span class="anchor" id="line-718"></span><span class="anchor" id="line-719"></span><span class="anchor" id="line-720"></span><span class="anchor" id="line-721"></span><span class="anchor" id="line-722"></span><span class="anchor" id="line-723"></span><span class="anchor" id="line-724"></span><span class="anchor" id="line-725"></span><span class="anchor" id="line-726"></span><span class="anchor" id="line-727"></span><span class="anchor" id="line-728"></span><span class="anchor" id="line-729"></span><span class="anchor" id="line-730"></span><span class="anchor" id="line-731"></span><span class="anchor" id="line-732"></span><span class="anchor" id="line-733"></span><span class="anchor" id="line-734"></span><span class="anchor" id="line-735"></span><span class="anchor" id="line-736"></span><span class="anchor" id="line-737"></span><span class="anchor" id="line-738"></span><span class="anchor" id="line-739"></span><span class="anchor" id="line-740"></span><span class="anchor" id="line-741"></span><span class="anchor" id="line-742"></span><span class="anchor" id="line-743"></span><span class="anchor" id="line-744"></span><span class="anchor" id="line-745"></span><span class="anchor" id="line-746"></span><span class="anchor" id="line-747"></span><span class="anchor" id="line-748"></span><span class="anchor" id="line-749"></span><span class="anchor" id="line-750"></span><span class="anchor" id="line-751"></span><span class="anchor" id="line-752"></span><span class="anchor" id="line-753"></span><span class="anchor" id="line-754"></span><span class="anchor" id="line-755"></span><span class="anchor" id="line-756"></span><span class="anchor" id="line-757"></span><span class="anchor" id="line-758"></span><span class="anchor" id="line-759"></span><span class="anchor" id="line-760"></span><span class="anchor" id="line-761"></span><span class="anchor" id="line-762"></span><span class="anchor" id="line-763"></span><span class="anchor" id="line-764"></span><span class="anchor" id="line-765"></span><span class="anchor" id="line-766"></span><span class="anchor" id="line-767"></span><span class="anchor" id="line-768"></span><span class="anchor" id="line-769"></span><span class="anchor" id="line-770"></span><span class="anchor" id="line-771"></span><span class="anchor" id="line-772"></span><span class="anchor" id="line-773"></span><span class="anchor" id="line-774"></span><span class="anchor" id="line-775"></span><span class="anchor" id="line-776"></span><span class="anchor" id="line-777"></span><span class="anchor" id="line-778"></span><span class="anchor" id="line-779"></span><span class="anchor" id="line-780"></span><span class="anchor" id="line-781"></span><span class="anchor" id="line-782"></span><span class="anchor" id="line-783"></span><span class="anchor" id="line-784"></span><span class="anchor" id="line-785"></span><span class="anchor" id="line-786"></span><span class="anchor" id="line-787"></span><span class="anchor" id="line-788"></span><span class="anchor" id="line-789"></span><span class="anchor" id="line-790"></span><span class="anchor" id="line-791"></span><span class="anchor" id="line-792"></span><span class="anchor" id="line-793"></span><span class="anchor" id="line-794"></span><span class="anchor" id="line-795"></span><span class="anchor" id="line-796"></span><span class="anchor" id="line-797"></span><span class="anchor" id="line-798"></span><span class="anchor" id="line-799"></span><span class="anchor" id="line-800"></span><span class="anchor" id="line-801"></span><span class="anchor" id="line-802"></span><span class="anchor" id="line-803"></span><span class="anchor" id="line-804"></span><span class="anchor" id="line-805"></span><span class="anchor" id="line-806"></span><span class="anchor" id="line-807"></span><span class="anchor" id="line-808"></span><span class="anchor" id="line-809"></span><span class="anchor" id="line-810"></span><span class="anchor" id="line-811"></span><span class="anchor" id="line-812"></span><span class="anchor" id="line-813"></span><span class="anchor" id="line-814"></span><span class="anchor" id="line-815"></span><span class="anchor" id="line-816"></span><span class="anchor" id="line-817"></span><span class="anchor" id="line-818"></span><span class="anchor" id="line-819"></span><span class="anchor" id="line-820"></span><span class="anchor" id="line-821"></span><span class="anchor" id="line-822"></span><span class="anchor" id="line-823"></span><span class="anchor" id="line-824"></span><span class="anchor" id="line-825"></span><span class="anchor" id="line-826"></span><span class="anchor" id="line-827"></span><span class="anchor" id="line-828"></span><span class="anchor" id="line-829"></span><span class="anchor" id="line-830"></span><span class="anchor" id="line-831"></span><span class="anchor" id="line-832"></span><span class="anchor" id="line-833"></span><span class="anchor" id="line-834"></span><span class="anchor" id="line-835"></span><span class="anchor" id="line-836"></span><span class="anchor" id="line-837"></span><span class="anchor" id="line-838"></span><span class="anchor" id="line-839"></span><span class="anchor" id="line-840"></span><span class="anchor" id="line-841"></span><span class="anchor" id="line-842"></span><span class="anchor" id="line-843"></span><span class="anchor" id="line-844"></span><span class="anchor" id="line-845"></span><span class="anchor" id="line-846"></span><span class="anchor" id="line-847"></span><span class="anchor" id="line-848"></span><span class="anchor" id="line-849"></span><span class="anchor" id="line-850"></span><span class="anchor" id="line-851"></span><span class="anchor" id="line-852"></span><span class="anchor" id="line-853"></span><span class="anchor" id="line-854"></span><span class="anchor" id="line-855"></span><span class="anchor" id="line-856"></span><span class="anchor" id="line-857"></span><span class="anchor" id="line-858"></span><span class="anchor" id="line-859"></span><span class="anchor" id="line-860"></span><span class="anchor" id="line-861"></span><span class="anchor" id="line-862"></span><span class="anchor" id="line-863"></span><span class="anchor" id="line-864"></span><span class="anchor" id="line-865"></span><span class="anchor" id="line-866"></span><span class="anchor" id="line-867"></span><span class="anchor" id="line-868"></span><span class="anchor" id="line-869"></span><span class="anchor" id="line-870"></span><span class="anchor" id="line-871"></span><span class="anchor" id="line-872"></span><span class="anchor" id="line-873"></span><span class="anchor" id="line-874"></span><span class="anchor" id="line-875"></span><span class="anchor" id="line-876"></span><span class="anchor" id="line-877"></span><span class="anchor" id="line-878"></span><span class="anchor" id="line-879"></span><span class="anchor" id="line-880"></span><span class="anchor" id="line-881"></span><span class="anchor" id="line-882"></span><span class="anchor" id="line-883"></span><span class="anchor" id="line-884"></span><span class="anchor" id="line-885"></span><span class="anchor" id="line-886"></span><span class="anchor" id="line-887"></span><span class="anchor" id="line-888"></span><span class="anchor" id="line-889"></span><span class="anchor" id="line-890"></span><span class="anchor" id="line-891"></span><span class="anchor" id="line-892"></span><span class="anchor" id="line-893"></span><span class="anchor" id="line-894"></span><span class="anchor" id="line-895"></span><span class="anchor" id="line-896"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-083267e5f0584adad570f55673906e4513d890f7\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-083267e5f0584adad570f55673906e4513d890f7', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-083267e5f0584adad570f55673906e4513d890f7" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># calculator.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ResWord">class</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   8 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span></span>
<span class="line"><span class="LineNumber">  10 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">DefaultPosition</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Size</span><span class="Operator">(</span><span class="Number">300</span><span class="Operator">,</span> <span class="Number">250</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  11 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">formula</span> <span class="Operator">=</span> <span class="ID">False</span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">menubar</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MenuBar</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">file</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Menu</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">file</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="Number">22</span><span class="Operator">,</span> <span class="String">'&amp;Quit'</span><span class="Operator">,</span> <span class="String">'Exit Calculator'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">menubar</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="ID">file</span><span class="Operator">,</span> <span class="String">'&amp;File'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetMenuBar</span><span class="Operator">(</span><span class="ID">menubar</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_MENU</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">22</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnClose</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  18 </span>        <span class="ID">sizer</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BoxSizer</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">VERTICAL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  19 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">display</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TextCtrl</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">,</span>  <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">TE_RIGHT</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  20 </span>        <span class="ID">sizer</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">display</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TOP</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BOTTOM</span><span class="Operator">,</span> <span class="Number">4</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  21 </span></span>
<span class="line"><span class="LineNumber">  22 </span>        <span class="ID">gs</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">GridSizer</span><span class="Operator">(</span><span class="Number">4</span><span class="Operator">,</span> <span class="Number">4</span><span class="Operator">,</span> <span class="Number">3</span><span class="Operator">,</span> <span class="Number">3</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  23 </span>        <span class="ID">gs</span><span class="Operator">.</span><span class="ID">AddMany</span><span class="Operator">(</span><span class="Operator">[</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">20</span><span class="Operator">,</span> <span class="String">'Cls'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  24 </span>                        <span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">21</span><span class="Operator">,</span> <span class="String">'Bck'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  25 </span>                        <span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  26 </span>                        <span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">22</span><span class="Operator">,</span> <span class="String">'Close'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  27 </span>                        <span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="String">'7'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  28 </span>                        <span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">2</span><span class="Operator">,</span> <span class="String">'8'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  29 </span>                        <span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">3</span><span class="Operator">,</span> <span class="String">'9'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  30 </span>                        <span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">4</span><span class="Operator">,</span> <span class="String">'/'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  31 </span>                        <span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">5</span><span class="Operator">,</span> <span class="String">'4'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  32 </span>                        <span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">6</span><span class="Operator">,</span> <span class="String">'5'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  33 </span>                        <span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">7</span><span class="Operator">,</span> <span class="String">'6'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  34 </span>                        <span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">8</span><span class="Operator">,</span> <span class="String">'*'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  35 </span>                        <span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">9</span><span class="Operator">,</span> <span class="String">'1'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  36 </span>                        <span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">10</span><span class="Operator">,</span> <span class="String">'2'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  37 </span>                        <span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">11</span><span class="Operator">,</span> <span class="String">'3'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  38 </span>                        <span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">12</span><span class="Operator">,</span> <span class="String">'-'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  39 </span>                        <span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">13</span><span class="Operator">,</span> <span class="String">'0'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  40 </span>                        <span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">14</span><span class="Operator">,</span> <span class="String">'.'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  41 </span>                        <span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">15</span><span class="Operator">,</span> <span class="String">'='</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  42 </span>                        <span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">16</span><span class="Operator">,</span> <span class="String">'+'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span> <span class="Operator">]</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  43 </span></span>
<span class="line"><span class="LineNumber">  44 </span>        <span class="ID">sizer</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">gs</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  45 </span></span>
<span class="line"><span class="LineNumber">  46 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetSizer</span><span class="Operator">(</span><span class="ID">sizer</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  47 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  48 </span></span>
<span class="line"><span class="LineNumber">  49 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnClear</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">20</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  50 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnBackspace</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">21</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  51 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnClose</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">22</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  52 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnSeven</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  53 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnEight</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">2</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  54 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnNine</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">3</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  55 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnDivide</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">4</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  56 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnFour</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">5</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  57 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnFive</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">6</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  58 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnSix</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">7</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  59 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnMultiply</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">8</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  60 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnOne</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">9</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  61 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnTwo</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">10</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  62 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnThree</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">11</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  63 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnMinus</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">12</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  64 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnZero</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">13</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  65 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnDot</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">14</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  66 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnEqual</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">15</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  67 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnPlus</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">16</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  68 </span></span>
<span class="line"><span class="LineNumber">  69 </span>    <span class="ResWord">def</span> <span class="ID">OnClear</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  70 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">display</span><span class="Operator">.</span><span class="ID">Clear</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  71 </span></span>
<span class="line"><span class="LineNumber">  72 </span>    <span class="ResWord">def</span> <span class="ID">OnBackspace</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  73 </span>        <span class="ID">formula</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">display</span><span class="Operator">.</span><span class="ID">GetValue</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  74 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">display</span><span class="Operator">.</span><span class="ID">Clear</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  75 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">display</span><span class="Operator">.</span><span class="ID">SetValue</span><span class="Operator">(</span><span class="ID">formula</span><span class="Operator">[</span><span class="Operator">:</span><span class="Operator">-</span><span class="Number">1</span><span class="Operator">]</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  76 </span></span>
<span class="line"><span class="LineNumber">  77 </span>    <span class="ResWord">def</span> <span class="ID">OnClose</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  78 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Close</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  79 </span></span>
<span class="line"><span class="LineNumber">  80 </span>    <span class="ResWord">def</span> <span class="ID">OnDivide</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  81 </span>        <span class="ResWord">if</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">formula</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  82 </span>            <span class="ResWord">return</span></span>
<span class="line"><span class="LineNumber">  83 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">display</span><span class="Operator">.</span><span class="ID">AppendText</span><span class="Operator">(</span><span class="String">'/'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  84 </span></span>
<span class="line"><span class="LineNumber">  85 </span>    <span class="ResWord">def</span> <span class="ID">OnMultiply</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  86 </span>        <span class="ResWord">if</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">formula</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  87 </span>            <span class="ResWord">return</span></span>
<span class="line"><span class="LineNumber">  88 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">display</span><span class="Operator">.</span><span class="ID">AppendText</span><span class="Operator">(</span><span class="String">'*'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  89 </span></span>
<span class="line"><span class="LineNumber">  90 </span>    <span class="ResWord">def</span> <span class="ID">OnMinus</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  91 </span>        <span class="ResWord">if</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">formula</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  92 </span>            <span class="ResWord">return</span></span>
<span class="line"><span class="LineNumber">  93 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">display</span><span class="Operator">.</span><span class="ID">AppendText</span><span class="Operator">(</span><span class="String">'-'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  94 </span></span>
<span class="line"><span class="LineNumber">  95 </span>    <span class="ResWord">def</span> <span class="ID">OnPlus</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  96 </span>        <span class="ResWord">if</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">formula</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  97 </span>            <span class="ResWord">return</span></span>
<span class="line"><span class="LineNumber">  98 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">display</span><span class="Operator">.</span><span class="ID">AppendText</span><span class="Operator">(</span><span class="String">'+'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  99 </span></span>
<span class="line"><span class="LineNumber"> 100 </span>    <span class="ResWord">def</span> <span class="ID">OnDot</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 101 </span>        <span class="ResWord">if</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">formula</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 102 </span>            <span class="ResWord">return</span></span>
<span class="line"><span class="LineNumber"> 103 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">display</span><span class="Operator">.</span><span class="ID">AppendText</span><span class="Operator">(</span><span class="String">'.'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 104 </span></span>
<span class="line"><span class="LineNumber"> 105 </span>    <span class="ResWord">def</span> <span class="ID">OnEqual</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 106 </span>        <span class="ResWord">if</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">formula</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 107 </span>            <span class="ResWord">return</span></span>
<span class="line"><span class="LineNumber"> 108 </span>        <span class="ID">formula</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">display</span><span class="Operator">.</span><span class="ID">GetValue</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 109 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">formula</span> <span class="Operator">=</span> <span class="ID">False</span></span>
<span class="line"><span class="LineNumber"> 110 </span>        <span class="ResWord">try</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 111 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">display</span><span class="Operator">.</span><span class="ID">Clear</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 112 </span>            <span class="ID">output</span> <span class="Operator">=</span> <span class="ID">eval</span><span class="Operator">(</span><span class="ID">formula</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 113 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">display</span><span class="Operator">.</span><span class="ID">AppendText</span><span class="Operator">(</span><span class="ID">str</span><span class="Operator">(</span><span class="ID">output</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 114 </span>        <span class="ResWord">except</span> <span class="ID">StandardError</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 115 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">display</span><span class="Operator">.</span><span class="ID">AppendText</span><span class="Operator">(</span><span class="String">"Error"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 116 </span></span>
<span class="line"><span class="LineNumber"> 117 </span>    <span class="ResWord">def</span> <span class="ID">OnZero</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 118 </span>        <span class="ResWord">if</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">formula</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 119 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">display</span><span class="Operator">.</span><span class="ID">Clear</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 120 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">formula</span> <span class="Operator">=</span> <span class="ID">False</span></span>
<span class="line"><span class="LineNumber"> 121 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">display</span><span class="Operator">.</span><span class="ID">AppendText</span><span class="Operator">(</span><span class="String">'0'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 122 </span></span>
<span class="line"><span class="LineNumber"> 123 </span>    <span class="ResWord">def</span> <span class="ID">OnOne</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 124 </span>        <span class="ResWord">if</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">formula</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 125 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">display</span><span class="Operator">.</span><span class="ID">Clear</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 126 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">formula</span> <span class="Operator">=</span> <span class="ID">False</span></span>
<span class="line"><span class="LineNumber"> 127 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">display</span><span class="Operator">.</span><span class="ID">AppendText</span><span class="Operator">(</span><span class="String">'1'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 128 </span></span>
<span class="line"><span class="LineNumber"> 129 </span>    <span class="ResWord">def</span> <span class="ID">OnTwo</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 130 </span>        <span class="ResWord">if</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">formula</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 131 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">display</span><span class="Operator">.</span><span class="ID">Clear</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 132 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">formula</span> <span class="Operator">=</span> <span class="ID">False</span></span>
<span class="line"><span class="LineNumber"> 133 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">display</span><span class="Operator">.</span><span class="ID">AppendText</span><span class="Operator">(</span><span class="String">'2'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 134 </span></span>
<span class="line"><span class="LineNumber"> 135 </span>    <span class="ResWord">def</span> <span class="ID">OnThree</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 136 </span>        <span class="ResWord">if</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">formula</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 137 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">display</span><span class="Operator">.</span><span class="ID">Clear</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 138 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">formula</span> <span class="Operator">=</span> <span class="ID">False</span></span>
<span class="line"><span class="LineNumber"> 139 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">display</span><span class="Operator">.</span><span class="ID">AppendText</span><span class="Operator">(</span><span class="String">'3'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 140 </span></span>
<span class="line"><span class="LineNumber"> 141 </span>    <span class="ResWord">def</span> <span class="ID">OnFour</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 142 </span>        <span class="ResWord">if</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">formula</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 143 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">display</span><span class="Operator">.</span><span class="ID">Clear</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 144 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">formula</span> <span class="Operator">=</span> <span class="ID">False</span></span>
<span class="line"><span class="LineNumber"> 145 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">display</span><span class="Operator">.</span><span class="ID">AppendText</span><span class="Operator">(</span><span class="String">'4'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 146 </span></span>
<span class="line"><span class="LineNumber"> 147 </span>    <span class="ResWord">def</span> <span class="ID">OnFive</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 148 </span>        <span class="ResWord">if</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">formula</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 149 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">display</span><span class="Operator">.</span><span class="ID">Clear</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 150 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">formula</span> <span class="Operator">=</span> <span class="ID">False</span></span>
<span class="line"><span class="LineNumber"> 151 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">display</span><span class="Operator">.</span><span class="ID">AppendText</span><span class="Operator">(</span><span class="String">'5'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 152 </span></span>
<span class="line"><span class="LineNumber"> 153 </span>    <span class="ResWord">def</span> <span class="ID">OnSix</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 154 </span>        <span class="ResWord">if</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">formula</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 155 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">display</span><span class="Operator">.</span><span class="ID">Clear</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 156 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">formula</span> <span class="Operator">=</span> <span class="ID">False</span></span>
<span class="line"><span class="LineNumber"> 157 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">display</span><span class="Operator">.</span><span class="ID">AppendText</span><span class="Operator">(</span><span class="String">'6'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 158 </span></span>
<span class="line"><span class="LineNumber"> 159 </span>    <span class="ResWord">def</span> <span class="ID">OnSeven</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 160 </span>        <span class="ResWord">if</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">formula</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 161 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">display</span><span class="Operator">.</span><span class="ID">Clear</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 162 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">formula</span> <span class="Operator">=</span> <span class="ID">False</span></span>
<span class="line"><span class="LineNumber"> 163 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">display</span><span class="Operator">.</span><span class="ID">AppendText</span><span class="Operator">(</span><span class="String">'7'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 164 </span></span>
<span class="line"><span class="LineNumber"> 165 </span>    <span class="ResWord">def</span> <span class="ID">OnEight</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 166 </span>        <span class="ResWord">if</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">formula</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 167 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">display</span><span class="Operator">.</span><span class="ID">Clear</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 168 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">formula</span> <span class="Operator">=</span> <span class="ID">False</span></span>
<span class="line"><span class="LineNumber"> 169 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">display</span><span class="Operator">.</span><span class="ID">AppendText</span><span class="Operator">(</span><span class="String">'8'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 170 </span></span>
<span class="line"><span class="LineNumber"> 171 </span>    <span class="ResWord">def</span> <span class="ID">OnNine</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 172 </span>        <span class="ResWord">if</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">formula</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 173 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">display</span><span class="Operator">.</span><span class="ID">Clear</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 174 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">formula</span> <span class="Operator">=</span> <span class="ID">False</span></span>
<span class="line"><span class="LineNumber"> 175 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">display</span><span class="Operator">.</span><span class="ID">AppendText</span><span class="Operator">(</span><span class="String">'9'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 176 </span></span>
<span class="line"><span class="LineNumber"> 177 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 178 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 179 </span>        <span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'calculator.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 180 </span>        <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 181 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetTopWindow</span><span class="Operator">(</span><span class="ID">frame</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 182 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber"> 183 </span></span>
<span class="line"><span class="LineNumber"> 184 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 185 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-897"></span><p class="line874">The formula we input is processed by the eval built-in python function. <span class="anchor" id="line-898"></span><span class="anchor" id="line-899"></span></p><p class="line867"><span class="anchor" id="line-900"></span><span class="anchor" id="line-901"></span></p><pre>output = eval(formula)</pre><span class="anchor" id="line-902"></span><p class="line862">If
 we make an error in our formula, an error message is displayed. Notice 
how we managed to put a space between the Bck and Close buttons. We 
simply put an empty <tt>wx.StaticText&nbsp;there</tt>. Such tricks are quite common. <span class="anchor" id="line-903"></span><span class="anchor" id="line-904"></span></p><p class="line867"><img alt="calculator.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_055.png" title="calculator.png"> <span class="anchor" id="line-905"></span><span class="anchor" id="line-906"></span></p><p class="line867"><strong>Figure: calculator.py</strong> <span class="anchor" id="line-907"></span><span class="anchor" id="line-908"></span></p><p class="line867">
</p><h3 id="wx.GridBagSizer">wx.GridBagSizer</h3>
<span class="anchor" id="line-909"></span><p class="line862">The most 
complicated sizer in wxPython. It enables explicit positioning of the 
items. Items can also optionally span more than one row and/or column. <tt>wx.GridBagSizer</tt> has a simple constructor. <span class="anchor" id="line-910"></span><span class="anchor" id="line-911"></span></p><p class="line867"><span class="anchor" id="line-912"></span><span class="anchor" id="line-913"></span></p><pre>wx.GridBagSizer(integer vgap, integer hgap)</pre><span class="anchor" id="line-914"></span><p class="line874">The
 vertical and the horizontal gap defines the space in pixels used 
between children. You add items to grid with the Add() method. <span class="anchor" id="line-915"></span><span class="anchor" id="line-916"></span></p><p class="line867"><span class="anchor" id="line-917"></span><span class="anchor" id="line-918"></span></p><pre>Add(self, item, tuple pos, tuple span=wx.DefaultSpan, integer flag=0, integer border=0, userData=None)</pre><span class="anchor" id="line-919"></span><p class="line862">Item
 is a widget that you insert into the grid. pos specifies the position 
in the virtual grid. The topleft cell has pos of (0, 0). span is an 
optional spanning of the widget. e.g. span of (3, 2) spans a widget 
across 3 rows and 2 columns. flag and border were discussed earlier by <tt>wx.BoxSizer</tt>. <span class="anchor" id="line-920"></span><span class="anchor" id="line-921"></span></p><p class="line874">The
 items in the grid can change their size or keep the default size, when 
the window is resized.  If you want your items to grow and shrink, you 
can use these two methods. <span class="anchor" id="line-922"></span><span class="anchor" id="line-923"></span></p><p class="line867"><span class="anchor" id="line-924"></span><span class="anchor" id="line-925"></span><span class="anchor" id="line-926"></span></p><pre>AddGrowableRow(integer row)
AddGrowableCol(integer col)</pre><span class="anchor" id="line-927"></span><p class="line867"><span class="anchor" id="line-928"></span><span class="anchor" id="line-929"></span><span class="anchor" id="line-930"></span><span class="anchor" id="line-931"></span><span class="anchor" id="line-932"></span><span class="anchor" id="line-933"></span><span class="anchor" id="line-934"></span><span class="anchor" id="line-935"></span><span class="anchor" id="line-936"></span><span class="anchor" id="line-937"></span><span class="anchor" id="line-938"></span><span class="anchor" id="line-939"></span><span class="anchor" id="line-940"></span><span class="anchor" id="line-941"></span><span class="anchor" id="line-942"></span><span class="anchor" id="line-943"></span><span class="anchor" id="line-944"></span><span class="anchor" id="line-945"></span><span class="anchor" id="line-946"></span><span class="anchor" id="line-947"></span><span class="anchor" id="line-948"></span><span class="anchor" id="line-949"></span><span class="anchor" id="line-950"></span><span class="anchor" id="line-951"></span><span class="anchor" id="line-952"></span><span class="anchor" id="line-953"></span><span class="anchor" id="line-954"></span><span class="anchor" id="line-955"></span><span class="anchor" id="line-956"></span><span class="anchor" id="line-957"></span><span class="anchor" id="line-958"></span><span class="anchor" id="line-959"></span><span class="anchor" id="line-960"></span><span class="anchor" id="line-961"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-5c3b39bd29d1c6562d032de4eaf89bc8487588fb\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-5c3b39bd29d1c6562d032de4eaf89bc8487588fb', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-5c3b39bd29d1c6562d032de4eaf89bc8487588fb" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># wxgridbagsizer.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ResWord">class</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   8 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">DefaultPosition</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  10 </span></span>
<span class="line"><span class="LineNumber">  11 </span>        <span class="ID">sizer</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">GridBagSizer</span><span class="Operator">(</span><span class="Number">9</span><span class="Operator">,</span> <span class="Number">9</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">sizer</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span><span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">"Button"</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">0</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">DefaultSpan</span><span class="Operator">,</span>  <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALL</span><span class="Operator">,</span> <span class="Number">5</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">sizer</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span><span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">"Button"</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">1</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">1</span><span class="Operator">,</span><span class="Number">7</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">sizer</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span><span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">"Button"</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">6</span><span class="Operator">,</span> <span class="Number">6</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">3</span><span class="Operator">,</span><span class="Number">3</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">sizer</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span><span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">"Button"</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">3</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">1</span><span class="Operator">,</span><span class="Number">1</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_CENTER</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span>        <span class="ID">sizer</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span><span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">"Button"</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">4</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">1</span><span class="Operator">,</span><span class="Number">1</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_LEFT</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="ID">sizer</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span><span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">"Button"</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">5</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">1</span><span class="Operator">,</span><span class="Number">1</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_RIGHT</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  18 </span>        <span class="ID">sizer</span><span class="Operator">.</span><span class="ID">AddGrowableRow</span><span class="Operator">(</span><span class="Number">6</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  19 </span>        <span class="ID">sizer</span><span class="Operator">.</span><span class="ID">AddGrowableCol</span><span class="Operator">(</span><span class="Number">6</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  20 </span></span>
<span class="line"><span class="LineNumber">  21 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetSizerAndFit</span><span class="Operator">(</span><span class="ID">sizer</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  22 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  23 </span></span>
<span class="line"><span class="LineNumber">  24 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  25 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  26 </span>        <span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">"wxgridbagsizer.py"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  27 </span>        <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  28 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetTopWindow</span><span class="Operator">(</span><span class="ID">frame</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  29 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  30 </span></span>
<span class="line"><span class="LineNumber">  31 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  32 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-962"></span><p class="line862">If you want your item to span more than one cell, you must provide <tt>wx.EXPAND</tt> flag. <span class="anchor" id="line-963"></span><span class="anchor" id="line-964"></span></p><p class="line867"><span class="anchor" id="line-965"></span><span class="anchor" id="line-966"></span></p><pre>self.SetSizerAndFit(sizer)</pre><span class="anchor" id="line-967"></span><p class="line862">This method is same as <tt>SetSizer()</tt> except that it also sends size hints to the window. All buttons are displayed on the window. <span class="anchor" id="line-968"></span><span class="anchor" id="line-969"></span></p><p class="line867">
</p><h2 id="Basic_Objects">Basic Objects</h2>
<span class="anchor" id="line-970"></span><p class="line874">wxPython is a collection of various objects. We can divide them into two groups. <span class="anchor" id="line-971"></span><span class="anchor" id="line-972"></span></p><ul><li>Visual objects <span class="anchor" id="line-973"></span></li><li>Non-visual objects <span class="anchor" id="line-974"></span><span class="anchor" id="line-975"></span></li></ul><p class="line874">Examples of visual objects are: widgets, fonts, colours or cursors. Non-visual objects: sizers, timers or events. <span class="anchor" id="line-976"></span><span class="anchor" id="line-977"></span></p><p class="line867">
</p><h3 id="Cursors">Cursors</h3>
<span class="anchor" id="line-978"></span><p class="line874">A cursor is
 a simple graphical object. It is used to indicate position on the 
monitor or any other display device. It usually dynamically changes 
itself. Typically, when you hover a mouse pointer over a hypertext, the 
cursor changes to a hand. <span class="anchor" id="line-979"></span><span class="anchor" id="line-980"></span></p><p class="line862">In the next code example, we create a grid of nine <tt>wx.Panels</tt>. Each panel shows a different cursor. <span class="anchor" id="line-981"></span><span class="anchor" id="line-982"></span></p><p class="line867"><span class="anchor" id="line-983"></span><span class="anchor" id="line-984"></span><span class="anchor" id="line-985"></span><span class="anchor" id="line-986"></span><span class="anchor" id="line-987"></span><span class="anchor" id="line-988"></span><span class="anchor" id="line-989"></span><span class="anchor" id="line-990"></span><span class="anchor" id="line-991"></span><span class="anchor" id="line-992"></span><span class="anchor" id="line-993"></span><span class="anchor" id="line-994"></span><span class="anchor" id="line-995"></span><span class="anchor" id="line-996"></span><span class="anchor" id="line-997"></span><span class="anchor" id="line-998"></span><span class="anchor" id="line-999"></span><span class="anchor" id="line-1000"></span><span class="anchor" id="line-1001"></span><span class="anchor" id="line-1002"></span><span class="anchor" id="line-1003"></span><span class="anchor" id="line-1004"></span><span class="anchor" id="line-1005"></span><span class="anchor" id="line-1006"></span><span class="anchor" id="line-1007"></span><span class="anchor" id="line-1008"></span><span class="anchor" id="line-1009"></span><span class="anchor" id="line-1010"></span><span class="anchor" id="line-1011"></span><span class="anchor" id="line-1012"></span><span class="anchor" id="line-1013"></span><span class="anchor" id="line-1014"></span><span class="anchor" id="line-1015"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-6120d6e921a3f4605f80832b65c2e3b5d1d904e9\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-6120d6e921a3f4605f80832b65c2e3b5d1d904e9', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-6120d6e921a3f4605f80832b65c2e3b5d1d904e9" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># cursors.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ResWord">class</span> <span class="ID">Cursors</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   8 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  10 </span></span>
<span class="line"><span class="LineNumber">  11 </span>        <span class="ID">vbox</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BoxSizer</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">VERTICAL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">sizer</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">GridSizer</span><span class="Operator">(</span><span class="Number">3</span><span class="Operator">,</span> <span class="Number">3</span><span class="Operator">,</span> <span class="Number">2</span><span class="Operator">,</span> <span class="Number">2</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">cursors</span> <span class="Operator">=</span> <span class="Operator">[</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">CURSOR_ARROW</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">CURSOR_HAND</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">CURSOR_WATCH</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">CURSOR_SPRAYCAN</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">CURSOR_PENCIL</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  15 </span>                    <span class="ID">wx</span><span class="Operator">.</span><span class="ID">CURSOR_CROSS</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">CURSOR_QUESTION_ARROW</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">CURSOR_POINT_LEFT</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">CURSOR_SIZING</span><span class="Operator">]</span></span>
<span class="line"><span class="LineNumber">  16 </span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="ResWord">for</span> <span class="ID">i</span> <span class="ResWord">in</span> <span class="ID">cursors</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  18 </span>            <span class="ID">panel</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">SUNKEN_BORDER</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  19 </span>            <span class="ID">panel</span><span class="Operator">.</span><span class="ID">SetCursor</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">StockCursor</span><span class="Operator">(</span><span class="ID">i</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  20 </span>            <span class="ID">sizer</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="ID">flag</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  21 </span></span>
<span class="line"><span class="LineNumber">  22 </span>        <span class="ID">vbox</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">sizer</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TOP</span><span class="Operator">,</span> <span class="Number">5</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  23 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetSizer</span><span class="Operator">(</span><span class="ID">vbox</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  24 </span></span>
<span class="line"><span class="LineNumber">  25 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  26 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  27 </span></span>
<span class="line"><span class="LineNumber">  28 </span></span>
<span class="line"><span class="LineNumber">  29 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  30 </span><span class="ID">Cursors</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Cursors.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  31 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-1016"></span><p class="line862">Various predefined cursors: <a href="http://wiki.wxpython.org/AnotherTutorial#head-26c168844e79da5329d8463baa7511fff18a6c5c">Listed below.</a> <span class="anchor" id="line-1017"></span><span class="anchor" id="line-1018"></span></p><p class="line867">
</p><h3 id="Fonts">Fonts</h3>
<span class="anchor" id="line-1019"></span><p class="line874">We create different kinds of fonts with the wx.Font object. It has the following constructor: <span class="anchor" id="line-1020"></span><span class="anchor" id="line-1021"></span></p><p class="line867"><span class="anchor" id="line-1022"></span><span class="anchor" id="line-1023"></span><span class="anchor" id="line-1024"></span><span class="anchor" id="line-1025"></span></p><pre>wx.Font(integer pointSize, wx.FontFamily family, integer style, integer weight,
        bool underline = false, string faceName = '',
        wx.FontEncoding encoding = wx.FONTENCODING_DEFAULT)</pre><span class="anchor" id="line-1026"></span><p class="line874">The specified parameters can have the following options: <span class="anchor" id="line-1027"></span><span class="anchor" id="line-1028"></span></p><p class="line874">family: <span class="anchor" id="line-1029"></span><span class="anchor" id="line-1030"></span></p><ul><li>wx.DEFAULT <span class="anchor" id="line-1031"></span></li><li>wx.DECORATIVE <span class="anchor" id="line-1032"></span></li><li>wx.ROMAN <span class="anchor" id="line-1033"></span></li><li>wx.SWISS <span class="anchor" id="line-1034"></span></li><li>wx.SCRIPT <span class="anchor" id="line-1035"></span></li><li>wx.MODERN <span class="anchor" id="line-1036"></span><span class="anchor" id="line-1037"></span></li></ul><p class="line874">style: <span class="anchor" id="line-1038"></span><span class="anchor" id="line-1039"></span></p><ul><li>wx.NORMAL <span class="anchor" id="line-1040"></span></li><li>wx.SLANT <span class="anchor" id="line-1041"></span></li><li>wx.ITALIC <span class="anchor" id="line-1042"></span><span class="anchor" id="line-1043"></span></li></ul><p class="line874">weight: <span class="anchor" id="line-1044"></span><span class="anchor" id="line-1045"></span></p><ul><li>wx.NORMAL <span class="anchor" id="line-1046"></span></li><li>wx.LIGHT <span class="anchor" id="line-1047"></span></li><li>wx.BOLD <span class="anchor" id="line-1048"></span><span class="anchor" id="line-1049"></span></li></ul><p class="line874">fonts.py script shows three different fonts. <span class="anchor" id="line-1050"></span><span class="anchor" id="line-1051"></span></p><p class="line867"><span class="anchor" id="line-1052"></span><span class="anchor" id="line-1053"></span><span class="anchor" id="line-1054"></span><span class="anchor" id="line-1055"></span><span class="anchor" id="line-1056"></span><span class="anchor" id="line-1057"></span><span class="anchor" id="line-1058"></span><span class="anchor" id="line-1059"></span><span class="anchor" id="line-1060"></span><span class="anchor" id="line-1061"></span><span class="anchor" id="line-1062"></span><span class="anchor" id="line-1063"></span><span class="anchor" id="line-1064"></span><span class="anchor" id="line-1065"></span><span class="anchor" id="line-1066"></span><span class="anchor" id="line-1067"></span><span class="anchor" id="line-1068"></span><span class="anchor" id="line-1069"></span><span class="anchor" id="line-1070"></span><span class="anchor" id="line-1071"></span><span class="anchor" id="line-1072"></span><span class="anchor" id="line-1073"></span><span class="anchor" id="line-1074"></span><span class="anchor" id="line-1075"></span><span class="anchor" id="line-1076"></span><span class="anchor" id="line-1077"></span><span class="anchor" id="line-1078"></span><span class="anchor" id="line-1079"></span><span class="anchor" id="line-1080"></span><span class="anchor" id="line-1081"></span><span class="anchor" id="line-1082"></span><span class="anchor" id="line-1083"></span><span class="anchor" id="line-1084"></span><span class="anchor" id="line-1085"></span><span class="anchor" id="line-1086"></span><span class="anchor" id="line-1087"></span><span class="anchor" id="line-1088"></span><span class="anchor" id="line-1089"></span><span class="anchor" id="line-1090"></span><span class="anchor" id="line-1091"></span><span class="anchor" id="line-1092"></span><span class="anchor" id="line-1093"></span><span class="anchor" id="line-1094"></span><span class="anchor" id="line-1095"></span><span class="anchor" id="line-1096"></span><span class="anchor" id="line-1097"></span><span class="anchor" id="line-1098"></span><span class="anchor" id="line-1099"></span><span class="anchor" id="line-1100"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-338c6ec7b864631f98a192c786e620141eb31d5d\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-338c6ec7b864631f98a192c786e620141eb31d5d', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-338c6ec7b864631f98a192c786e620141eb31d5d" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># fonts.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ResWord">class</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   8 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">DefaultPosition</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Size</span><span class="Operator">(</span><span class="Number">325</span><span class="Operator">,</span> <span class="Number">320</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  10 </span></span>
<span class="line"><span class="LineNumber">  11 </span>        <span class="ID">panel</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  12 </span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">text1</span> <span class="Operator">=</span> <span class="String">"Now listen to me mama\nMama mama\nYou're taking away my last chance\nDon't take it away"</span></span>
<span class="line"><span class="LineNumber">  14 </span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">text2</span> <span class="Operator">=</span> <span class="String">'''You won't cry for my absence, I know -</span></span>
<span class="line"><span class="LineNumber">  16 </span><span class="String">You forgot me long ago.</span></span>
<span class="line"><span class="LineNumber">  17 </span><span class="String">Am I that unimportant...?</span></span>
<span class="line"><span class="LineNumber">  18 </span><span class="String">Am I so insignificant...?</span></span>
<span class="line"><span class="LineNumber">  19 </span><span class="String">Isn't something missing?</span></span>
<span class="line"><span class="LineNumber">  20 </span><span class="String">Isn't someone missing me?'''</span></span>
<span class="line"><span class="LineNumber">  21 </span></span>
<span class="line"><span class="LineNumber">  22 </span>        <span class="ID">text3</span> <span class="Operator">=</span> <span class="String">'''But if I had one wish fulfilled tonight</span></span>
<span class="line"><span class="LineNumber">  23 </span><span class="String">I'd ask for the sun to never rise</span></span>
<span class="line"><span class="LineNumber">  24 </span><span class="String">If God passed a mic to me to speak</span></span>
<span class="line"><span class="LineNumber">  25 </span><span class="String">I'd say stay in bed, world</span></span>
<span class="line"><span class="LineNumber">  26 </span><span class="String">Sleep in peace'''</span></span>
<span class="line"><span class="LineNumber">  27 </span></span>
<span class="line"><span class="LineNumber">  28 </span>        <span class="ID">font1</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Font</span><span class="Operator">(</span><span class="Number">10</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">NORMAL</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ITALIC</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">NORMAL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  29 </span>        <span class="ID">font2</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Font</span><span class="Operator">(</span><span class="Number">10</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ROMAN</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">NORMAL</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">NORMAL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  30 </span>        <span class="ID">font3</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Font</span><span class="Operator">(</span><span class="Number">10</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MODERN</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">NORMAL</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BOLD</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  31 </span>        <span class="ID">lyrics1</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">text1</span><span class="Operator">,</span><span class="Operator">(</span><span class="Number">30</span><span class="Operator">,</span><span class="Number">15</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_CENTRE</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  32 </span>        <span class="ID">lyrics1</span><span class="Operator">.</span><span class="ID">SetFont</span><span class="Operator">(</span><span class="ID">font1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  33 </span>        <span class="ID">lyrics2</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">text2</span><span class="Operator">,</span><span class="Operator">(</span><span class="Number">30</span><span class="Operator">,</span><span class="Number">100</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_CENTRE</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  34 </span>        <span class="ID">lyrics2</span><span class="Operator">.</span><span class="ID">SetFont</span><span class="Operator">(</span><span class="ID">font2</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  35 </span>        <span class="ID">lyrics3</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">text3</span><span class="Operator">,</span><span class="Operator">(</span><span class="Number">5</span><span class="Operator">,</span><span class="Number">220</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_CENTRE</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  36 </span>        <span class="ID">lyrics3</span><span class="Operator">.</span><span class="ID">SetFont</span><span class="Operator">(</span><span class="ID">font3</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  37 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Center</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  38 </span></span>
<span class="line"><span class="LineNumber">  39 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  40 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  41 </span>        <span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'fonts.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  42 </span>        <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  43 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetTopWindow</span><span class="Operator">(</span><span class="ID">frame</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  44 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  45 </span></span>
<span class="line"><span class="LineNumber">  46 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  47 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-1101"></span><p class="line867"><img alt="fonts.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_031.png" title="fonts.png"> <span class="anchor" id="line-1102"></span><span class="anchor" id="line-1103"></span></p><p class="line867"><strong>Figure: fonts.py</strong> <span class="anchor" id="line-1104"></span><span class="anchor" id="line-1105"></span></p><p class="line867">
</p><h3 id="Colours">Colours</h3>
<span class="anchor" id="line-1106"></span><p class="line874">A colour 
is an object representing a combination of Red, Green, and Blue (RGB) 
intensity values.  Valid RGB values are in the range 0 to 255. <span class="anchor" id="line-1107"></span><span class="anchor" id="line-1108"></span></p><p class="line874">There
 are three ways for setting colours. We can create a wx.Colour object, 
use a predefined colour name or  use hex value string. <span class="anchor" id="line-1109"></span><span class="anchor" id="line-1110"></span></p><p class="line867"><span class="anchor" id="line-1111"></span><span class="anchor" id="line-1112"></span><span class="anchor" id="line-1113"></span><span class="anchor" id="line-1114"></span></p><pre>SetBackgroundColour(wx.Colour(0,0,255))
SetBackgroundColour('BLUE')
SetBackgroundColour('#0000FF')</pre><span class="anchor" id="line-1115"></span><p class="line874">Predefined colour names in wxPython: <span class="anchor" id="line-1116"></span><span class="anchor" id="line-1117"></span></p><ul><li>wx.BLACK <span class="anchor" id="line-1118"></span></li><li>wx.WHITE <span class="anchor" id="line-1119"></span></li><li>wx.RED <span class="anchor" id="line-1120"></span></li><li>wx.BLUE <span class="anchor" id="line-1121"></span></li><li>wx.GREEN <span class="anchor" id="line-1122"></span></li><li>wx.CYAN <span class="anchor" id="line-1123"></span></li><li>wx.LIGHT_GREY <span class="anchor" id="line-1124"></span><span class="anchor" id="line-1125"></span></li></ul><p class="line874">Standard colour database: <span class="anchor" id="line-1126"></span><span class="anchor" id="line-1127"></span></p><p class="line867"><a href="http://wiki.wxpython.org/AnotherTutorial#head-dda5ab503215d8330883aa21c0a396add53bada8">Listed below.</a> <span class="anchor" id="line-1128"></span><span class="anchor" id="line-1129"></span></p><p class="line874">colours.py
 script shows eight different colours. wxBlack is simple. sea green is 
poetic and #0000FF technical. It is up to the developer, what to choose.
 <span class="anchor" id="line-1130"></span><span class="anchor" id="line-1131"></span></p><p class="line867"><span class="anchor" id="line-1132"></span><span class="anchor" id="line-1133"></span><span class="anchor" id="line-1134"></span><span class="anchor" id="line-1135"></span><span class="anchor" id="line-1136"></span><span class="anchor" id="line-1137"></span><span class="anchor" id="line-1138"></span><span class="anchor" id="line-1139"></span><span class="anchor" id="line-1140"></span><span class="anchor" id="line-1141"></span><span class="anchor" id="line-1142"></span><span class="anchor" id="line-1143"></span><span class="anchor" id="line-1144"></span><span class="anchor" id="line-1145"></span><span class="anchor" id="line-1146"></span><span class="anchor" id="line-1147"></span><span class="anchor" id="line-1148"></span><span class="anchor" id="line-1149"></span><span class="anchor" id="line-1150"></span><span class="anchor" id="line-1151"></span><span class="anchor" id="line-1152"></span><span class="anchor" id="line-1153"></span><span class="anchor" id="line-1154"></span><span class="anchor" id="line-1155"></span><span class="anchor" id="line-1156"></span><span class="anchor" id="line-1157"></span><span class="anchor" id="line-1158"></span><span class="anchor" id="line-1159"></span><span class="anchor" id="line-1160"></span><span class="anchor" id="line-1161"></span><span class="anchor" id="line-1162"></span><span class="anchor" id="line-1163"></span><span class="anchor" id="line-1164"></span><span class="anchor" id="line-1165"></span><span class="anchor" id="line-1166"></span><span class="anchor" id="line-1167"></span><span class="anchor" id="line-1168"></span><span class="anchor" id="line-1169"></span><span class="anchor" id="line-1170"></span><span class="anchor" id="line-1171"></span><span class="anchor" id="line-1172"></span><span class="anchor" id="line-1173"></span><span class="anchor" id="line-1174"></span><span class="anchor" id="line-1175"></span><span class="anchor" id="line-1176"></span><span class="anchor" id="line-1177"></span><span class="anchor" id="line-1178"></span><span class="anchor" id="line-1179"></span><span class="anchor" id="line-1180"></span><span class="anchor" id="line-1181"></span><span class="anchor" id="line-1182"></span><span class="anchor" id="line-1183"></span><span class="anchor" id="line-1184"></span><span class="anchor" id="line-1185"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-c0ca189e5e85d8527fa6548914e0a840f29255bd\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-c0ca189e5e85d8527fa6548914e0a840f29255bd', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-c0ca189e5e85d8527fa6548914e0a840f29255bd" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># colours.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span></span>
<span class="line"><span class="LineNumber">   8 </span><span class="ResWord">class</span> <span class="ID">Colours</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Dialog</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  10 </span></span>
<span class="line"><span class="LineNumber">  11 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Dialog</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">300</span><span class="Operator">,</span> <span class="Number">300</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">vbox</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BoxSizer</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">VERTICAL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">pnl1</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">pnl2</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">pnl3</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">pnl4</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">pnl5</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  18 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">pnl6</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  19 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">pnl7</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  20 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">pnl8</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  21 </span></span>
<span class="line"><span class="LineNumber">  22 </span>        <span class="ID">gs</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">GridSizer</span><span class="Operator">(</span><span class="Number">4</span><span class="Operator">,</span><span class="Number">2</span><span class="Operator">,</span><span class="Number">3</span><span class="Operator">,</span><span class="Number">3</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  23 </span>        <span class="ID">gs</span><span class="Operator">.</span><span class="ID">AddMany</span><span class="Operator">(</span><span class="Operator">[</span> <span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">pnl1</span><span class="Operator">,</span> <span class="Number">0</span> <span class="Operator">,</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  24 </span>            <span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">pnl2</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  25 </span>            <span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">pnl3</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  26 </span>            <span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">pnl4</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  27 </span>            <span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">pnl5</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  28 </span>            <span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">pnl6</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  29 </span>            <span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">pnl7</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  30 </span>            <span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">pnl8</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span> <span class="Operator">]</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  31 </span></span>
<span class="line"><span class="LineNumber">  32 </span>        <span class="ID">vbox</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">gs</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TOP</span><span class="Operator">,</span> <span class="Number">5</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  33 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetSizer</span><span class="Operator">(</span><span class="ID">vbox</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  34 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetColors</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  35 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  36 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">ShowModal</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  37 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Destroy</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  38 </span></span>
<span class="line"><span class="LineNumber">  39 </span>    <span class="ResWord">def</span> <span class="ID">SetColors</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  40 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">pnl1</span><span class="Operator">.</span><span class="ID">SetBackgroundColour</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">BLACK</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  41 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">pnl2</span><span class="Operator">.</span><span class="ID">SetBackgroundColour</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Colour</span><span class="Operator">(</span><span class="Number">139</span><span class="Operator">,</span><span class="Number">105</span><span class="Operator">,</span><span class="Number">20</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  42 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">pnl3</span><span class="Operator">.</span><span class="ID">SetBackgroundColour</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">RED</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  43 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">pnl4</span><span class="Operator">.</span><span class="ID">SetBackgroundColour</span><span class="Operator">(</span><span class="String">'#0000FF'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  44 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">pnl5</span><span class="Operator">.</span><span class="ID">SetBackgroundColour</span><span class="Operator">(</span><span class="String">'sea green'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  45 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">pnl6</span><span class="Operator">.</span><span class="ID">SetBackgroundColour</span><span class="Operator">(</span><span class="String">'midnight blue'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  46 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">pnl7</span><span class="Operator">.</span><span class="ID">SetBackgroundColour</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">LIGHT_GREY</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  47 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">pnl8</span><span class="Operator">.</span><span class="ID">SetBackgroundColour</span><span class="Operator">(</span><span class="String">'plum'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  48 </span></span>
<span class="line"><span class="LineNumber">  49 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  50 </span><span class="ID">Colours</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'colours.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  51 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-1186"></span><p class="line867"><img alt="colours.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_038.png" title="colours.png"> <span class="anchor" id="line-1187"></span><span class="anchor" id="line-1188"></span></p><p class="line867"><strong>Figure: colours.py</strong> <span class="anchor" id="line-1189"></span><span class="anchor" id="line-1190"></span></p><p class="line874">The
 full database has currently about 630 different colour names. The list 
can be found in the colourdb.py file. It is also shown in the wxPython 
demo. In randomcolours.py script we have a single window. We change the 
background colour of the window to the randomly chosen colour. <span class="anchor" id="line-1191"></span><span class="anchor" id="line-1192"></span></p><p class="line867"><span class="anchor" id="line-1193"></span><span class="anchor" id="line-1194"></span><span class="anchor" id="line-1195"></span><span class="anchor" id="line-1196"></span><span class="anchor" id="line-1197"></span><span class="anchor" id="line-1198"></span><span class="anchor" id="line-1199"></span><span class="anchor" id="line-1200"></span><span class="anchor" id="line-1201"></span><span class="anchor" id="line-1202"></span><span class="anchor" id="line-1203"></span><span class="anchor" id="line-1204"></span><span class="anchor" id="line-1205"></span><span class="anchor" id="line-1206"></span><span class="anchor" id="line-1207"></span><span class="anchor" id="line-1208"></span><span class="anchor" id="line-1209"></span><span class="anchor" id="line-1210"></span><span class="anchor" id="line-1211"></span><span class="anchor" id="line-1212"></span><span class="anchor" id="line-1213"></span><span class="anchor" id="line-1214"></span><span class="anchor" id="line-1215"></span><span class="anchor" id="line-1216"></span><span class="anchor" id="line-1217"></span><span class="anchor" id="line-1218"></span><span class="anchor" id="line-1219"></span><span class="anchor" id="line-1220"></span><span class="anchor" id="line-1221"></span><span class="anchor" id="line-1222"></span><span class="anchor" id="line-1223"></span><span class="anchor" id="line-1224"></span><span class="anchor" id="line-1225"></span><span class="anchor" id="line-1226"></span><span class="anchor" id="line-1227"></span><span class="anchor" id="line-1228"></span><span class="anchor" id="line-1229"></span><span class="anchor" id="line-1230"></span><span class="anchor" id="line-1231"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-4a0e84f868c4861b781269ec61288cfe0dee41fb\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-4a0e84f868c4861b781269ec61288cfe0dee41fb', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-4a0e84f868c4861b781269ec61288cfe0dee41fb" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># randomcolours.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ResWord">from</span> <span class="ID">random</span> <span class="ResWord">import</span> <span class="ID">randrange</span></span>
<span class="line"><span class="LineNumber">   8 </span><span class="ResWord">from</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">lib</span><span class="Operator">.</span><span class="ID">colourdb</span> <span class="ResWord">import</span> <span class="Operator">*</span></span>
<span class="line"><span class="LineNumber">   9 </span></span>
<span class="line"><span class="LineNumber">  10 </span><span class="ResWord">class</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  11 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">DefaultPosition</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Size</span><span class="Operator">(</span><span class="Number">400</span><span class="Operator">,</span> <span class="Number">350</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">panel</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">colors</span> <span class="Operator">=</span> <span class="ID">getColourList</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">timer</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Timer</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_TIMER</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnTimer</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">timer</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  18 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">timer</span><span class="Operator">.</span><span class="ID">Start</span><span class="Operator">(</span><span class="Number">1500</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  19 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">col_num</span> <span class="Operator">=</span> <span class="ID">len</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">colors</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  20 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  21 </span></span>
<span class="line"><span class="LineNumber">  22 </span>    <span class="ResWord">def</span> <span class="ID">OnTimer</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  23 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">panel</span><span class="Operator">.</span><span class="ID">SetBackgroundColour</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">RED</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  24 </span>        <span class="ID">position</span> <span class="Operator">=</span> <span class="ID">randrange</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">col_num</span><span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  25 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">panel</span><span class="Operator">.</span><span class="ID">SetBackgroundColour</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">colors</span><span class="Operator">[</span><span class="ID">position</span><span class="Operator">]</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  26 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">panel</span><span class="Operator">.</span><span class="ID">Refresh</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  27 </span></span>
<span class="line"><span class="LineNumber">  28 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  29 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  30 </span>        <span class="ID">updateColourDB</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  31 </span>        <span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'randomcolours.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  32 </span>        <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  33 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetTopWindow</span><span class="Operator">(</span><span class="ID">frame</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  34 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  35 </span></span>
<span class="line"><span class="LineNumber">  36 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  37 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-1232"></span><p class="line867">
</p><h3 id="Bitmaps">Bitmaps</h3>
<span class="anchor" id="line-1233"></span><p class="line862">There are two kinds of graphics. <strong>Vector</strong> and <strong>bitmap</strong>.
  With vector graphics, images are created with mathematical formulas 
that define all the shapes of the image. Geometric objects like curves 
and polygons are used.  A bitmap or a bit map is a collection of bits 
that form an image. It is a grid of individual dots stored in memory or 
in a file. Each dot has it's own colour. When the image is displayed, 
the computer transfers a bit map into pixels on monitors or ink dots on 
printers. The quality of a bitmap is determined by the <strong>resolution</strong> and the <strong>color depth</strong>
 of the image.  The resolution is the total number of pixels in the 
image. The Color depth is the amount of information in each pixel. <span class="anchor" id="line-1234"></span><span class="anchor" id="line-1235"></span></p><p class="line874">There are various kinds of bitmaps: <span class="anchor" id="line-1236"></span><span class="anchor" id="line-1237"></span></p><ul><li>PNG <span class="anchor" id="line-1238"></span></li><li>JPEG <span class="anchor" id="line-1239"></span></li><li>GIF <span class="anchor" id="line-1240"></span></li><li>TIFF <span class="anchor" id="line-1241"></span></li><li>BMP <span class="anchor" id="line-1242"></span><span class="anchor" id="line-1243"></span></li></ul><p class="line867"><span class="anchor" id="line-1244"></span><span class="anchor" id="line-1245"></span><span class="anchor" id="line-1246"></span><span class="anchor" id="line-1247"></span><span class="anchor" id="line-1248"></span><span class="anchor" id="line-1249"></span><span class="anchor" id="line-1250"></span><span class="anchor" id="line-1251"></span><span class="anchor" id="line-1252"></span><span class="anchor" id="line-1253"></span><span class="anchor" id="line-1254"></span><span class="anchor" id="line-1255"></span><span class="anchor" id="line-1256"></span><span class="anchor" id="line-1257"></span><span class="anchor" id="line-1258"></span><span class="anchor" id="line-1259"></span><span class="anchor" id="line-1260"></span><span class="anchor" id="line-1261"></span><span class="anchor" id="line-1262"></span><span class="anchor" id="line-1263"></span><span class="anchor" id="line-1264"></span><span class="anchor" id="line-1265"></span><span class="anchor" id="line-1266"></span><span class="anchor" id="line-1267"></span><span class="anchor" id="line-1268"></span><span class="anchor" id="line-1269"></span><span class="anchor" id="line-1270"></span><span class="anchor" id="line-1271"></span><span class="anchor" id="line-1272"></span><span class="anchor" id="line-1273"></span><span class="anchor" id="line-1274"></span><span class="anchor" id="line-1275"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-052887a28c597fb5f718f8d99b57e907a57c9eaf\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-052887a28c597fb5f718f8d99b57e907a57c9eaf', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-052887a28c597fb5f718f8d99b57e907a57c9eaf" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># bitmap.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ResWord">class</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   8 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">size</span> <span class="Operator">=</span> <span class="Operator">(</span><span class="Number">270</span><span class="Operator">,</span> <span class="Number">270</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  10 </span></span>
<span class="line"><span class="LineNumber">  11 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">bitmap</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bitmap</span><span class="Operator">(</span><span class="String">'memento.jpg'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_PAINT</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnPaint</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span></span>
<span class="line"><span class="LineNumber">  16 </span>    <span class="ResWord">def</span> <span class="ID">OnPaint</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="ID">dc</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">PaintDC</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  18 </span>        <span class="ID">dc</span><span class="Operator">.</span><span class="ID">DrawBitmap</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">bitmap</span><span class="Operator">,</span> <span class="Number">60</span><span class="Operator">,</span> <span class="Number">20</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  19 </span></span>
<span class="line"><span class="LineNumber">  20 </span></span>
<span class="line"><span class="LineNumber">  21 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  22 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  23 </span>        <span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Memento'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  24 </span>        <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  25 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetTopWindow</span><span class="Operator">(</span><span class="ID">frame</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  26 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  27 </span></span>
<span class="line"><span class="LineNumber">  28 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  29 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-1276"></span><p class="line867"><img alt="memento.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_053.png" title="memento.png"> <span class="anchor" id="line-1277"></span><span class="anchor" id="line-1278"></span></p><p class="line867"><strong>Figure:</strong> bitmap.py <span class="anchor" id="line-1279"></span><span class="anchor" id="line-1280"></span></p><p class="line867">
</p><h2 id="Events">Events</h2>
<span class="anchor" id="line-1281"></span><p class="line862">Events are
 integral part of every GUI application. All GUI applications are 
event-driven. An application reacts to different event types which are 
generated during it's life. Events are generated mainly by the user of 
an application.  But they can be generated by other means as well. e.g. 
internet connection, window manager, timer.  So when we call <tt>MainLoop()</tt> method, our application waits for events to be generated. The <tt>MainLoop()</tt> method ends when we exit the application. <span class="anchor" id="line-1282"></span><span class="anchor" id="line-1283"></span></p><p class="line874">Working with events is straightforward in wxPython. There are three steps: <span class="anchor" id="line-1284"></span><span class="anchor" id="line-1285"></span></p><ul><li>Identify the event name: wx.EVT_SIZE, wx.EVT_CLOSE etc <span class="anchor" id="line-1286"></span></li><li>Create an event handler. It is a method, that is called, when an event is generated <span class="anchor" id="line-1287"></span></li><li>Bind an event to an event handler. <span class="anchor" id="line-1288"></span><span class="anchor" id="line-1289"></span></li></ul><p class="line874">In wxPython we say to bind a method to an event. Sometimes a word hook is used. <span class="anchor" id="line-1290"></span><span class="anchor" id="line-1291"></span></p><p class="line862">You bind an event by calling the <tt>Bind()</tt> method. The method has the following parameters: <span class="anchor" id="line-1292"></span><span class="anchor" id="line-1293"></span></p><p class="line867"><span class="anchor" id="line-1294"></span><span class="anchor" id="line-1295"></span></p><pre>Bind(event, handler, source=None, id=wx.ID_ANY, id2=wx.ID_ANY)</pre><span class="anchor" id="line-1296"></span><ul><li>event is one of EVT_* objects. It specifies the type of the event. <span class="anchor" id="line-1297"></span></li><li>handler is an object to be called. In other words, it is a method, that a programmer binds to an event. <span class="anchor" id="line-1298"></span></li><li>source parameter is used when we want to differentiate between the same event type from different widgets. <span class="anchor" id="line-1299"></span></li><li>id parameter is used, when we have multiple buttons, menu items etc.  The id is used to differentiate among them. <span class="anchor" id="line-1300"></span></li><li>id2 is used when it is desirable to bind a handler to a range of ids, such as with EVT_MENU_RANGE. <span class="anchor" id="line-1301"></span><span class="anchor" id="line-1302"></span></li></ul><p class="line862">Note that method <tt>Bind()</tt> is defined in class <tt>EvtHandler</tt>.
 It is the class, from which wx.Window inherits. wx.Window is a base 
class for most widgets in wxPython. There is also a reverse process. If 
we want to unbind a method from an event, we call the <tt>Unbind()</tt> method. It has the same paremeters as the above one. <span class="anchor" id="line-1303"></span></p><div><table><tbody><tr>  <td colspan="2" style="text-align: center;"><p class="line891"><strong>Possible events</strong> </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-1304"></span><p class="line891"><tt>wx.Event</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">the event base class </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-1305"></span><p class="line891"><tt>wx.ActivateEvent</tt> </p></td>
  <td><p class="line862">a window or application activation event </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-1306"></span><p class="line891"><tt>wx.CloseEvent</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">a close window or end session event </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-1307"></span><p class="line891"><tt>wx.EraseEvent</tt> </p></td>
  <td><p class="line862">an erase background event </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-1308"></span><p class="line891"><tt>wx.FocusEvent</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">a window focus event </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-1309"></span><p class="line891"><tt>wx.KeyEvent</tt> </p></td>
  <td><p class="line862">a keypress event </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-1310"></span><p class="line891"><tt>wx.IdleEvent</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">an idle event </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-1311"></span><p class="line891"><tt>wx.InitDialogEvent</tt> </p></td>
  <td><p class="line862">a dialog initialisation event </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-1312"></span><p class="line891"><tt>wx.JoystickEvent</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">a joystick event </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-1313"></span><p class="line891"><tt>wx.MenuEvent</tt> </p></td>
  <td><p class="line862">a menu event </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-1314"></span><p class="line891"><tt>wx.MouseEvent</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">a mouse event </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-1315"></span><p class="line891"><tt>wx.MoveEvent</tt> </p></td>
  <td><p class="line862">a move event </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-1316"></span><p class="line891"><tt>wx.PaintEvent</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">a paint event </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-1317"></span><p class="line891"><tt>wx.QueryLayoutInfoEvent</tt> </p></td>
  <td><p class="line862">used to query layout information </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-1318"></span><p class="line891"><tt>wx.SetCursorEvent</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">used for special cursor processing based on current mouse position </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-1319"></span><p class="line891"><tt>wx.SizeEvent</tt> </p></td>
  <td><p class="line862">a size event </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-1320"></span><p class="line891"><tt>wx.ScrollWinEvent</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">a scroll event sent by a built-in Scrollbar </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-1321"></span><p class="line891"><tt>wx.ScrollEvent</tt> </p></td>
  <td><p class="line862">a scroll event sent by a stand-alone scrollbar </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-1322"></span><p class="line891"><tt>wx.SysColourChangedEvent</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">a system colour change event </p></td>
</tr>
</tbody></table></div><span class="anchor" id="line-1323"></span><span class="anchor" id="line-1324"></span><span class="anchor" id="line-1325"></span><span class="anchor" id="line-1326"></span><span class="anchor" id="line-1327"></span><p class="line867">
</p><h3 id="Examples">Examples</h3>
<span class="anchor" id="line-1328"></span><p class="line862">The following code is an example of a <tt>wx.ScrollWinEvent</tt>. This event is generated, when we click on a built in Scrollbar. Built-in Scrollbar is activated with the <tt>SetScrollbar()</tt> method call. For stand-alone Scrollbars, there is another event type, namely <tt>wx.ScrollEvent</tt>. <span class="anchor" id="line-1329"></span><span class="anchor" id="line-1330"></span></p><p class="line867"><span class="anchor" id="line-1331"></span><span class="anchor" id="line-1332"></span><span class="anchor" id="line-1333"></span><span class="anchor" id="line-1334"></span><span class="anchor" id="line-1335"></span><span class="anchor" id="line-1336"></span><span class="anchor" id="line-1337"></span><span class="anchor" id="line-1338"></span><span class="anchor" id="line-1339"></span><span class="anchor" id="line-1340"></span><span class="anchor" id="line-1341"></span><span class="anchor" id="line-1342"></span><span class="anchor" id="line-1343"></span><span class="anchor" id="line-1344"></span><span class="anchor" id="line-1345"></span><span class="anchor" id="line-1346"></span><span class="anchor" id="line-1347"></span><span class="anchor" id="line-1348"></span><span class="anchor" id="line-1349"></span><span class="anchor" id="line-1350"></span><span class="anchor" id="line-1351"></span><span class="anchor" id="line-1352"></span><span class="anchor" id="line-1353"></span><span class="anchor" id="line-1354"></span><span class="anchor" id="line-1355"></span><span class="anchor" id="line-1356"></span><span class="anchor" id="line-1357"></span><span class="anchor" id="line-1358"></span><span class="anchor" id="line-1359"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-68eefbfc80ba7e1f71763de24878ad0f3f0309e7\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-68eefbfc80ba7e1f71763de24878ad0f3f0309e7', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-68eefbfc80ba7e1f71763de24878ad0f3f0309e7" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># myscrollwinevent.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ResWord">class</span> <span class="ID">MyScrollWinEvent</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   8 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  10 </span>        <span class="ID">panel</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  11 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">st</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'0'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">30</span><span class="Operator">,</span><span class="Number">0</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">panel</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_SCROLLWIN</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnScroll</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">panel</span><span class="Operator">.</span><span class="ID">SetScrollbar</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">VERTICAL</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="Number">6</span><span class="Operator">,</span> <span class="Number">50</span><span class="Operator">)</span><span class="Operator">;</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span></span>
<span class="line"><span class="LineNumber">  16 </span>    <span class="ResWord">def</span> <span class="ID">OnScroll</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">evt</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="ID">y</span> <span class="Operator">=</span> <span class="ID">evt</span><span class="Operator">.</span><span class="ID">GetPosition</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  18 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">st</span><span class="Operator">.</span><span class="ID">SetLabel</span><span class="Operator">(</span><span class="ID">str</span><span class="Operator">(</span><span class="ID">y</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  19 </span></span>
<span class="line"><span class="LineNumber">  20 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  21 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  22 </span>        <span class="ID">msw</span> <span class="Operator">=</span> <span class="ID">MyScrollWinEvent</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'myscrollwinevent.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  23 </span>        <span class="ID">msw</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  24 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  25 </span></span>
<span class="line"><span class="LineNumber">  26 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  27 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-1360"></span><p class="line862">The <tt>wx.SizeEvent</tt> is generated, when our window is resized. In our example, we show the size of the window in the titlebar. <span class="anchor" id="line-1361"></span><span class="anchor" id="line-1362"></span></p><p class="line867"><span class="anchor" id="line-1363"></span><span class="anchor" id="line-1364"></span><span class="anchor" id="line-1365"></span><span class="anchor" id="line-1366"></span><span class="anchor" id="line-1367"></span><span class="anchor" id="line-1368"></span><span class="anchor" id="line-1369"></span><span class="anchor" id="line-1370"></span><span class="anchor" id="line-1371"></span><span class="anchor" id="line-1372"></span><span class="anchor" id="line-1373"></span><span class="anchor" id="line-1374"></span><span class="anchor" id="line-1375"></span><span class="anchor" id="line-1376"></span><span class="anchor" id="line-1377"></span><span class="anchor" id="line-1378"></span><span class="anchor" id="line-1379"></span><span class="anchor" id="line-1380"></span><span class="anchor" id="line-1381"></span><span class="anchor" id="line-1382"></span><span class="anchor" id="line-1383"></span><span class="anchor" id="line-1384"></span><span class="anchor" id="line-1385"></span><span class="anchor" id="line-1386"></span><span class="anchor" id="line-1387"></span><span class="anchor" id="line-1388"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-fb943d63dbfb2bdf26b4ac6bbc91e53c30f0b50a\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-fb943d63dbfb2bdf26b4ac6bbc91e53c30f0b50a', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-fb943d63dbfb2bdf26b4ac6bbc91e53c30f0b50a" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># sizeevent.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ResWord">class</span> <span class="ID">SizeEvent</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   8 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  10 </span></span>
<span class="line"><span class="LineNumber">  11 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_SIZE</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnSize</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span></span>
<span class="line"><span class="LineNumber">  14 </span>    <span class="ResWord">def</span> <span class="ID">OnSize</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetTitle</span><span class="Operator">(</span><span class="ID">str</span><span class="Operator">(</span><span class="ID">event</span><span class="Operator">.</span><span class="ID">GetSize</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span></span>
<span class="line"><span class="LineNumber">  17 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  18 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  19 </span>        <span class="ID">se</span> <span class="Operator">=</span> <span class="ID">SizeEvent</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'sizeevent.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  20 </span>        <span class="ID">se</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  21 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  22 </span></span>
<span class="line"><span class="LineNumber">  23 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  24 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-1389"></span><p class="line867"><span class="anchor" id="line-1390"></span><span class="anchor" id="line-1391"></span><span class="anchor" id="line-1392"></span><span class="anchor" id="line-1393"></span><span class="anchor" id="line-1394"></span><span class="anchor" id="line-1395"></span><span class="anchor" id="line-1396"></span><span class="anchor" id="line-1397"></span><span class="anchor" id="line-1398"></span><span class="anchor" id="line-1399"></span><span class="anchor" id="line-1400"></span><span class="anchor" id="line-1401"></span><span class="anchor" id="line-1402"></span><span class="anchor" id="line-1403"></span><span class="anchor" id="line-1404"></span><span class="anchor" id="line-1405"></span><span class="anchor" id="line-1406"></span><span class="anchor" id="line-1407"></span><span class="anchor" id="line-1408"></span><span class="anchor" id="line-1409"></span><span class="anchor" id="line-1410"></span><span class="anchor" id="line-1411"></span><span class="anchor" id="line-1412"></span><span class="anchor" id="line-1413"></span><span class="anchor" id="line-1414"></span><span class="anchor" id="line-1415"></span><span class="anchor" id="line-1416"></span><span class="anchor" id="line-1417"></span><span class="anchor" id="line-1418"></span><span class="anchor" id="line-1419"></span><span class="anchor" id="line-1420"></span><span class="anchor" id="line-1421"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-02b6330e9680718f940ece52cf5629ed2fcbb4d8\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-02b6330e9680718f940ece52cf5629ed2fcbb4d8', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-02b6330e9680718f940ece52cf5629ed2fcbb4d8" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># moveevent.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ResWord">class</span> <span class="ID">MoveEvent</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   8 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  10 </span></span>
<span class="line"><span class="LineNumber">  11 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'x:'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">10</span><span class="Operator">,</span><span class="Number">0</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'y:'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">10</span><span class="Operator">,</span><span class="Number">20</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">st1</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">30</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">st2</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">30</span><span class="Operator">,</span> <span class="Number">20</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_MOVE</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnMove</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span></span>
<span class="line"><span class="LineNumber">  18 </span>    <span class="ResWord">def</span> <span class="ID">OnMove</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  19 </span>        <span class="ID">x</span><span class="Operator">,</span> <span class="ID">y</span> <span class="Operator">=</span> <span class="ID">event</span><span class="Operator">.</span><span class="ID">GetPosition</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  20 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">st1</span><span class="Operator">.</span><span class="ID">SetLabel</span><span class="Operator">(</span><span class="ID">str</span><span class="Operator">(</span><span class="ID">x</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  21 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">st2</span><span class="Operator">.</span><span class="ID">SetLabel</span><span class="Operator">(</span><span class="ID">str</span><span class="Operator">(</span><span class="ID">y</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  22 </span></span>
<span class="line"><span class="LineNumber">  23 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  24 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  25 </span>        <span class="ID">me</span> <span class="Operator">=</span> <span class="ID">MoveEvent</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'moveevent.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  26 </span>        <span class="ID">me</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  27 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  28 </span></span>
<span class="line"><span class="LineNumber">  29 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  30 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-1422"></span><p class="line862">A
 paint event is generated when a window is redrawn. This happens when we
 resize window, maximize it. A paint event can be generated 
programatically as well. For example, when we call <tt>SetLabel()</tt> method to change a <tt>wxStaticText</tt> widget. Note that when we minimize a window, no paint event is generated. <span class="anchor" id="line-1423"></span><span class="anchor" id="line-1424"></span></p><p class="line867"><span class="anchor" id="line-1425"></span><span class="anchor" id="line-1426"></span><span class="anchor" id="line-1427"></span><span class="anchor" id="line-1428"></span><span class="anchor" id="line-1429"></span><span class="anchor" id="line-1430"></span><span class="anchor" id="line-1431"></span><span class="anchor" id="line-1432"></span><span class="anchor" id="line-1433"></span><span class="anchor" id="line-1434"></span><span class="anchor" id="line-1435"></span><span class="anchor" id="line-1436"></span><span class="anchor" id="line-1437"></span><span class="anchor" id="line-1438"></span><span class="anchor" id="line-1439"></span><span class="anchor" id="line-1440"></span><span class="anchor" id="line-1441"></span><span class="anchor" id="line-1442"></span><span class="anchor" id="line-1443"></span><span class="anchor" id="line-1444"></span><span class="anchor" id="line-1445"></span><span class="anchor" id="line-1446"></span><span class="anchor" id="line-1447"></span><span class="anchor" id="line-1448"></span><span class="anchor" id="line-1449"></span><span class="anchor" id="line-1450"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-ae652a11c0129f0c10c604b6286a2263b30ca60a\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-ae652a11c0129f0c10c604b6286a2263b30ca60a', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-ae652a11c0129f0c10c604b6286a2263b30ca60a" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># paintevent.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ResWord">class</span> <span class="ID">PaintEvent</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   8 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  10 </span></span>
<span class="line"><span class="LineNumber">  11 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_PAINT</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnPaint</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span></span>
<span class="line"><span class="LineNumber">  14 </span>    <span class="ResWord">def</span> <span class="ID">OnPaint</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bell</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span></span>
<span class="line"><span class="LineNumber">  17 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  18 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  19 </span>        <span class="ID">pe</span> <span class="Operator">=</span> <span class="ID">PaintEvent</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'paintevent.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  20 </span>        <span class="ID">pe</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  21 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  22 </span></span>
<span class="line"><span class="LineNumber">  23 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  24 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-1451"></span><p class="line862">When we press a key on our keyboard, <tt>wx.KeyEvent</tt> is generated. There are three different key handlers: <span class="anchor" id="line-1452"></span><span class="anchor" id="line-1453"></span></p><ul><li>EVT_KEY_DOWN <span class="anchor" id="line-1454"></span></li><li>EVT_KEY_UP <span class="anchor" id="line-1455"></span></li><li>EVT_CHAR <span class="anchor" id="line-1456"></span><span class="anchor" id="line-1457"></span></li></ul><p class="line874">A common request is to close application, when Esc key is pressed. <span class="anchor" id="line-1458"></span><span class="anchor" id="line-1459"></span></p><p class="line867"><span class="anchor" id="line-1460"></span><span class="anchor" id="line-1461"></span><span class="anchor" id="line-1462"></span><span class="anchor" id="line-1463"></span><span class="anchor" id="line-1464"></span><span class="anchor" id="line-1465"></span><span class="anchor" id="line-1466"></span><span class="anchor" id="line-1467"></span><span class="anchor" id="line-1468"></span><span class="anchor" id="line-1469"></span><span class="anchor" id="line-1470"></span><span class="anchor" id="line-1471"></span><span class="anchor" id="line-1472"></span><span class="anchor" id="line-1473"></span><span class="anchor" id="line-1474"></span><span class="anchor" id="line-1475"></span><span class="anchor" id="line-1476"></span><span class="anchor" id="line-1477"></span><span class="anchor" id="line-1478"></span><span class="anchor" id="line-1479"></span><span class="anchor" id="line-1480"></span><span class="anchor" id="line-1481"></span><span class="anchor" id="line-1482"></span><span class="anchor" id="line-1483"></span><span class="anchor" id="line-1484"></span><span class="anchor" id="line-1485"></span><span class="anchor" id="line-1486"></span><span class="anchor" id="line-1487"></span><span class="anchor" id="line-1488"></span><span class="anchor" id="line-1489"></span><span class="anchor" id="line-1490"></span><span class="anchor" id="line-1491"></span><span class="anchor" id="line-1492"></span><span class="anchor" id="line-1493"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-5a4816deef3fefe5252dbcbedb18dbf1e4aea585\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-5a4816deef3fefe5252dbcbedb18dbf1e4aea585', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-5a4816deef3fefe5252dbcbedb18dbf1e4aea585" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># keyevent.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span></span>
<span class="line"><span class="LineNumber">   8 </span><span class="ResWord">class</span> <span class="ID">KeyEvent</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  10 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  11 </span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">panel</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">panel</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_KEY_DOWN</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnKeyDown</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">panel</span><span class="Operator">.</span><span class="ID">SetFocus</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span></span>
<span class="line"><span class="LineNumber">  16 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  18 </span></span>
<span class="line"><span class="LineNumber">  19 </span></span>
<span class="line"><span class="LineNumber">  20 </span>    <span class="ResWord">def</span> <span class="ID">OnKeyDown</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  21 </span>        <span class="ID">keycode</span> <span class="Operator">=</span> <span class="ID">event</span><span class="Operator">.</span><span class="ID">GetKeyCode</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  22 </span>        <span class="ResWord">if</span> <span class="ID">keycode</span> <span class="Operator">==</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">WXK_ESCAPE</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  23 </span>            <span class="ID">ret</span>  <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MessageBox</span><span class="Operator">(</span><span class="String">'Are you sure to quit?'</span><span class="Operator">,</span> <span class="String">'Question'</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">YES_NO</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">CENTRE</span> <span class="Operator">|</span></span>
<span class="line"><span class="LineNumber">  24 </span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">NO_DEFAULT</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  25 </span>            <span class="ResWord">if</span> <span class="ID">ret</span> <span class="Operator">==</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">YES</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  26 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">Close</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  27 </span>        <span class="ID">event</span><span class="Operator">.</span><span class="ID">Skip</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  28 </span></span>
<span class="line"><span class="LineNumber">  29 </span></span>
<span class="line"><span class="LineNumber">  30 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  31 </span><span class="ID">KeyEvent</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'keyevent.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  32 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-1494"></span><p class="line862">We find out, which key was pressed by calling <tt>GetKeyCode()</tt> method. In our case, keycode is wx.WXK_ESCAPE. <span class="anchor" id="line-1495"></span><span class="anchor" id="line-1496"></span></p><p class="line867"><span class="anchor" id="line-1497"></span><span class="anchor" id="line-1498"></span></p><pre>keycode = event.GetKeyCode()</pre><span class="anchor" id="line-1499"></span><p class="line862">Other keycodes are <a href="http://wiki.wxpython.org/AnotherTutorial#head-999ff1e3fbf5694a51a91cf4ed2140f692da013c">listed below.</a> <span class="anchor" id="line-1500"></span><span class="anchor" id="line-1501"></span></p><p class="line867">
</p><h2 id="Dialogs">Dialogs</h2>
<span class="anchor" id="line-1502"></span><p class="line874">In wxPython  you can use predefined dialogs or create your own dialogs. You can also create dialog based applications. <span class="anchor" id="line-1503"></span><span class="anchor" id="line-1504"></span></p><p class="line874">The example shows a skeleton of a dialog based application in wxPython. <span class="anchor" id="line-1505"></span><span class="anchor" id="line-1506"></span></p><p class="line867"><span class="anchor" id="line-1507"></span><span class="anchor" id="line-1508"></span><span class="anchor" id="line-1509"></span><span class="anchor" id="line-1510"></span><span class="anchor" id="line-1511"></span><span class="anchor" id="line-1512"></span><span class="anchor" id="line-1513"></span><span class="anchor" id="line-1514"></span><span class="anchor" id="line-1515"></span><span class="anchor" id="line-1516"></span><span class="anchor" id="line-1517"></span><span class="anchor" id="line-1518"></span><span class="anchor" id="line-1519"></span><span class="anchor" id="line-1520"></span><span class="anchor" id="line-1521"></span><span class="anchor" id="line-1522"></span><span class="anchor" id="line-1523"></span><span class="anchor" id="line-1524"></span><span class="anchor" id="line-1525"></span><span class="anchor" id="line-1526"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-37384c8d39f22f509050e09da02e072cb0be7a11\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-37384c8d39f22f509050e09da02e072cb0be7a11', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-37384c8d39f22f509050e09da02e072cb0be7a11" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span><span class="Comment"># simpledialog.py</span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   5 </span></span>
<span class="line"><span class="LineNumber">   6 </span><span class="ResWord">class</span> <span class="ID">MyDialog</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Dialog</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   7 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   8 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Dialog</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">   9 </span></span>
<span class="line"><span class="LineNumber">  10 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  11 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">dia</span> <span class="Operator">=</span> <span class="ID">MyDialog</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">"simpledialog.py"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">dia</span><span class="Operator">.</span><span class="ID">ShowModal</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">dia</span><span class="Operator">.</span><span class="ID">Destroy</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  16 </span></span>
<span class="line"><span class="LineNumber">  17 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  18 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-1527"></span><p class="line862">Notice that you cannot resize the dialog window.  The <tt>Destroy()</tt> method is necessary. It deletes the dialog from the memory. Otherwise, the script would not exit properly. <span class="anchor" id="line-1528"></span><span class="anchor" id="line-1529"></span></p><p class="line862">There
 are two types of dialogs. Modal and modeless. Modal dialog does not 
allow a user to work with the rest of the application until it is 
destroyed. Modal dialogs are created with the <tt>ShowModal()</tt> method. Dialogs are modeless  when called with <tt>Show()</tt>. <span class="anchor" id="line-1530"></span><span class="anchor" id="line-1531"></span></p><p class="line867">
</p><h3 id="Custom_dialogs">Custom dialogs</h3>
<span class="anchor" id="line-1532"></span><p class="line874">There are two methods that simplify the creation of dialogs.  Both return a specific sizer object. <span class="anchor" id="line-1533"></span><span class="anchor" id="line-1534"></span></p><p class="line867"><span class="anchor" id="line-1535"></span><span class="anchor" id="line-1536"></span><span class="anchor" id="line-1537"></span></p><pre>CreateTextSizer(self, string message)
CreateButtonSizer(self, long flags)</pre><span class="anchor" id="line-1538"></span><p class="line867"><tt>CreateTextSizer()</tt> method creates a text sizer.  In the following example, we add some buttons into the sizer to demonstrate it. <span class="anchor" id="line-1539"></span><span class="anchor" id="line-1540"></span></p><p class="line867"><span class="anchor" id="line-1541"></span><span class="anchor" id="line-1542"></span><span class="anchor" id="line-1543"></span><span class="anchor" id="line-1544"></span><span class="anchor" id="line-1545"></span><span class="anchor" id="line-1546"></span><span class="anchor" id="line-1547"></span><span class="anchor" id="line-1548"></span><span class="anchor" id="line-1549"></span><span class="anchor" id="line-1550"></span><span class="anchor" id="line-1551"></span><span class="anchor" id="line-1552"></span><span class="anchor" id="line-1553"></span><span class="anchor" id="line-1554"></span><span class="anchor" id="line-1555"></span><span class="anchor" id="line-1556"></span><span class="anchor" id="line-1557"></span><span class="anchor" id="line-1558"></span><span class="anchor" id="line-1559"></span><span class="anchor" id="line-1560"></span><span class="anchor" id="line-1561"></span><span class="anchor" id="line-1562"></span><span class="anchor" id="line-1563"></span><span class="anchor" id="line-1564"></span><span class="anchor" id="line-1565"></span><span class="anchor" id="line-1566"></span><span class="anchor" id="line-1567"></span><span class="anchor" id="line-1568"></span><span class="anchor" id="line-1569"></span><span class="anchor" id="line-1570"></span><span class="anchor" id="line-1571"></span><span class="anchor" id="line-1572"></span><span class="anchor" id="line-1573"></span><span class="anchor" id="line-1574"></span><span class="anchor" id="line-1575"></span><span class="anchor" id="line-1576"></span><span class="anchor" id="line-1577"></span><span class="anchor" id="line-1578"></span><span class="anchor" id="line-1579"></span><span class="anchor" id="line-1580"></span><span class="anchor" id="line-1581"></span><span class="anchor" id="line-1582"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-ba7f52ca3344e4c80a13a44f83e6bb04b9de32ce\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-ba7f52ca3344e4c80a13a44f83e6bb04b9de32ce', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-ba7f52ca3344e4c80a13a44f83e6bb04b9de32ce" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># customdialog1.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ResWord">class</span> <span class="ID">MyDialog</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Dialog</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   8 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Dialog</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">350</span><span class="Operator">,</span><span class="Number">300</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  10 </span></span>
<span class="line"><span class="LineNumber">  11 </span>        <span class="ID">sizer</span> <span class="Operator">=</span>  <span class="ID">self</span><span class="Operator">.</span><span class="ID">CreateTextSizer</span><span class="Operator">(</span><span class="String">'My Buttons'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">sizer</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Button'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALL</span><span class="Operator">,</span> <span class="Number">5</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">sizer</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Button'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALL</span><span class="Operator">,</span> <span class="Number">5</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">sizer</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Button'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALL</span><span class="Operator">,</span> <span class="Number">5</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">sizer</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Button'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALL</span><span class="Operator">|</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_CENTER</span><span class="Operator">,</span> <span class="Number">5</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span>        <span class="ID">sizer</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Button'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALL</span><span class="Operator">|</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">,</span> <span class="Number">5</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetSizer</span><span class="Operator">(</span><span class="ID">sizer</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  18 </span></span>
<span class="line"><span class="LineNumber">  19 </span><span class="ResWord">class</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  20 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  21 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">550</span><span class="Operator">,</span><span class="Number">500</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  22 </span></span>
<span class="line"><span class="LineNumber">  23 </span>        <span class="ID">panel</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  24 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="String">'Show Custom Dialog'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">100</span><span class="Operator">,</span><span class="Number">100</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  25 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span> <span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnShowCustomDialog</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  26 </span></span>
<span class="line"><span class="LineNumber">  27 </span>    <span class="ResWord">def</span> <span class="ID">OnShowCustomDialog</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  28 </span>        <span class="ID">dia</span> <span class="Operator">=</span> <span class="ID">MyDialog</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'buttons'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  29 </span>        <span class="ID">dia</span><span class="Operator">.</span><span class="ID">ShowModal</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  30 </span>        <span class="ID">dia</span><span class="Operator">.</span><span class="ID">Destroy</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  31 </span></span>
<span class="line"><span class="LineNumber">  32 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  33 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  34 </span>        <span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'customdialog1.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  35 </span>        <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  36 </span>        <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  37 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  38 </span></span>
<span class="line"><span class="LineNumber">  39 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  40 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-1583"></span><p class="line867"><tt>CreateButtonSizer()</tt> method creates a row of buttons. You can specify button types with different flags. <tt>CreateButtonSizer()</tt> method can take the following flags: <span class="anchor" id="line-1584"></span><span class="anchor" id="line-1585"></span></p><ul><li>wx.OK <span class="anchor" id="line-1586"></span></li><li>wx.CANCEL <span class="anchor" id="line-1587"></span></li><li>wx.YES <span class="anchor" id="line-1588"></span></li><li>wx.NO <span class="anchor" id="line-1589"></span></li><li>wx.HELP <span class="anchor" id="line-1590"></span></li><li>wx.NO_DEFAULT <span class="anchor" id="line-1591"></span><span class="anchor" id="line-1592"></span></li></ul><p class="line867"><span class="anchor" id="line-1593"></span><span class="anchor" id="line-1594"></span><span class="anchor" id="line-1595"></span><span class="anchor" id="line-1596"></span><span class="anchor" id="line-1597"></span><span class="anchor" id="line-1598"></span><span class="anchor" id="line-1599"></span><span class="anchor" id="line-1600"></span><span class="anchor" id="line-1601"></span><span class="anchor" id="line-1602"></span><span class="anchor" id="line-1603"></span><span class="anchor" id="line-1604"></span><span class="anchor" id="line-1605"></span><span class="anchor" id="line-1606"></span><span class="anchor" id="line-1607"></span><span class="anchor" id="line-1608"></span><span class="anchor" id="line-1609"></span><span class="anchor" id="line-1610"></span><span class="anchor" id="line-1611"></span><span class="anchor" id="line-1612"></span><span class="anchor" id="line-1613"></span><span class="anchor" id="line-1614"></span><span class="anchor" id="line-1615"></span><span class="anchor" id="line-1616"></span><span class="anchor" id="line-1617"></span><span class="anchor" id="line-1618"></span><span class="anchor" id="line-1619"></span><span class="anchor" id="line-1620"></span><span class="anchor" id="line-1621"></span><span class="anchor" id="line-1622"></span><span class="anchor" id="line-1623"></span><span class="anchor" id="line-1624"></span><span class="anchor" id="line-1625"></span><span class="anchor" id="line-1626"></span><span class="anchor" id="line-1627"></span><span class="anchor" id="line-1628"></span><span class="anchor" id="line-1629"></span><span class="anchor" id="line-1630"></span><span class="anchor" id="line-1631"></span><span class="anchor" id="line-1632"></span><span class="anchor" id="line-1633"></span><span class="anchor" id="line-1634"></span><span class="anchor" id="line-1635"></span><span class="anchor" id="line-1636"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-cf0040a62b0f9dc89065119290ee3f6bf42bfbfd\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-cf0040a62b0f9dc89065119290ee3f6bf42bfbfd', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-cf0040a62b0f9dc89065119290ee3f6bf42bfbfd" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># customdialog2.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ResWord">class</span> <span class="ID">MyDialog</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Dialog</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   8 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Dialog</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  10 </span></span>
<span class="line"><span class="LineNumber">  11 </span>        <span class="ID">vbox</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BoxSizer</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">VERTICAL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">stline</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">11</span><span class="Operator">,</span> <span class="String">'Discipline ist Macht.'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">vbox</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">stline</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_CENTER</span><span class="Operator">|</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">TOP</span><span class="Operator">,</span> <span class="Number">45</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">sizer</span> <span class="Operator">=</span>  <span class="ID">self</span><span class="Operator">.</span><span class="ID">CreateButtonSizer</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">NO</span><span class="Operator">|</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">YES</span><span class="Operator">|</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">HELP</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">vbox</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">sizer</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_CENTER</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetSizer</span><span class="Operator">(</span><span class="ID">vbox</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnYes</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">ID_YES</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  18 </span></span>
<span class="line"><span class="LineNumber">  19 </span>    <span class="ResWord">def</span> <span class="ID">OnYes</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  20 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Close</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  21 </span></span>
<span class="line"><span class="LineNumber">  22 </span><span class="ResWord">class</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  23 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  24 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  25 </span>        <span class="ID">panel</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  26 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="String">'Show custom Dialog'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">50</span><span class="Operator">,</span><span class="Number">50</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  27 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnShowCustomDialog</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  28 </span></span>
<span class="line"><span class="LineNumber">  29 </span>    <span class="ResWord">def</span> <span class="ID">OnShowCustomDialog</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  30 </span>        <span class="ID">dia</span> <span class="Operator">=</span> <span class="ID">MyDialog</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  31 </span>        <span class="ID">val</span> <span class="Operator">=</span> <span class="ID">dia</span><span class="Operator">.</span><span class="ID">ShowModal</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  32 </span>        <span class="ID">dia</span><span class="Operator">.</span><span class="ID">Destroy</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  33 </span></span>
<span class="line"><span class="LineNumber">  34 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  35 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  36 </span>        <span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'customdialog2.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  37 </span>        <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  38 </span>        <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  39 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  40 </span></span>
<span class="line"><span class="LineNumber">  41 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  42 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-1637"></span><p class="line874">Note that wxPython does not take the order of flags into account. <span class="anchor" id="line-1638"></span><span class="anchor" id="line-1639"></span></p><p class="line867"><span class="anchor" id="line-1640"></span><span class="anchor" id="line-1641"></span></p><pre>sizer =  self.CreateButtonSizer(wxNO|wxYES|wxHELP)</pre><span class="anchor" id="line-1642"></span><p class="line874">The buttons will be created according to the standards. <span class="anchor" id="line-1643"></span><span class="anchor" id="line-1644"></span></p><p class="line867">
</p><h3 id="Common_Predefined_Dialogs">Common Predefined Dialogs</h3>
<span class="anchor" id="line-1645"></span><p class="line874">wxPython 
provides several common dialogs. They save programmers a lot of work. 
They also help promote standards in applications. We will show these 
ones: <span class="anchor" id="line-1646"></span><span class="anchor" id="line-1647"></span></p><ul><li><p class="line891"><tt>wx.MessageDialog</tt> <span class="anchor" id="line-1648"></span></p></li><li><p class="line891"><tt>wx.ColourDialog</tt> <span class="anchor" id="line-1649"></span></p></li><li><p class="line891"><tt>wx.FileDialog</tt> <span class="anchor" id="line-1650"></span></p></li><li><p class="line891"><tt>wx.PageSetupDialog</tt> <span class="anchor" id="line-1651"></span></p></li><li><p class="line891"><tt>wx.FontDialog</tt> <span class="anchor" id="line-1652"></span></p></li><li><p class="line891"><tt>wx.DirDialog</tt> <span class="anchor" id="line-1653"></span></p></li><li><p class="line891"><tt>wx.SingleChoiceDialog</tt> <span class="anchor" id="line-1654"></span></p></li><li><p class="line891"><tt>wx.TextEntryDialog</tt> <span class="anchor" id="line-1655"></span><span class="anchor" id="line-1656"></span></p></li></ul><p class="line867"><span class="anchor" id="line-1657"></span><span class="anchor" id="line-1658"></span><span class="anchor" id="line-1659"></span><span class="anchor" id="line-1660"></span><span class="anchor" id="line-1661"></span><span class="anchor" id="line-1662"></span><span class="anchor" id="line-1663"></span><span class="anchor" id="line-1664"></span><span class="anchor" id="line-1665"></span><span class="anchor" id="line-1666"></span><span class="anchor" id="line-1667"></span><span class="anchor" id="line-1668"></span><span class="anchor" id="line-1669"></span><span class="anchor" id="line-1670"></span><span class="anchor" id="line-1671"></span><span class="anchor" id="line-1672"></span><span class="anchor" id="line-1673"></span><span class="anchor" id="line-1674"></span><span class="anchor" id="line-1675"></span><span class="anchor" id="line-1676"></span><span class="anchor" id="line-1677"></span><span class="anchor" id="line-1678"></span><span class="anchor" id="line-1679"></span><span class="anchor" id="line-1680"></span><span class="anchor" id="line-1681"></span><span class="anchor" id="line-1682"></span><span class="anchor" id="line-1683"></span><span class="anchor" id="line-1684"></span><span class="anchor" id="line-1685"></span><span class="anchor" id="line-1686"></span><span class="anchor" id="line-1687"></span><span class="anchor" id="line-1688"></span><span class="anchor" id="line-1689"></span><span class="anchor" id="line-1690"></span><span class="anchor" id="line-1691"></span><span class="anchor" id="line-1692"></span><span class="anchor" id="line-1693"></span><span class="anchor" id="line-1694"></span><span class="anchor" id="line-1695"></span><span class="anchor" id="line-1696"></span><span class="anchor" id="line-1697"></span><span class="anchor" id="line-1698"></span><span class="anchor" id="line-1699"></span><span class="anchor" id="line-1700"></span><span class="anchor" id="line-1701"></span><span class="anchor" id="line-1702"></span><span class="anchor" id="line-1703"></span><span class="anchor" id="line-1704"></span><span class="anchor" id="line-1705"></span><span class="anchor" id="line-1706"></span><span class="anchor" id="line-1707"></span><span class="anchor" id="line-1708"></span><span class="anchor" id="line-1709"></span><span class="anchor" id="line-1710"></span><span class="anchor" id="line-1711"></span><span class="anchor" id="line-1712"></span><span class="anchor" id="line-1713"></span><span class="anchor" id="line-1714"></span><span class="anchor" id="line-1715"></span><span class="anchor" id="line-1716"></span><span class="anchor" id="line-1717"></span><span class="anchor" id="line-1718"></span><span class="anchor" id="line-1719"></span><span class="anchor" id="line-1720"></span><span class="anchor" id="line-1721"></span><span class="anchor" id="line-1722"></span><span class="anchor" id="line-1723"></span><span class="anchor" id="line-1724"></span><span class="anchor" id="line-1725"></span><span class="anchor" id="line-1726"></span><span class="anchor" id="line-1727"></span><span class="anchor" id="line-1728"></span><span class="anchor" id="line-1729"></span><span class="anchor" id="line-1730"></span><span class="anchor" id="line-1731"></span><span class="anchor" id="line-1732"></span><span class="anchor" id="line-1733"></span><span class="anchor" id="line-1734"></span><span class="anchor" id="line-1735"></span><span class="anchor" id="line-1736"></span><span class="anchor" id="line-1737"></span><span class="anchor" id="line-1738"></span><span class="anchor" id="line-1739"></span><span class="anchor" id="line-1740"></span><span class="anchor" id="line-1741"></span><span class="anchor" id="line-1742"></span><span class="anchor" id="line-1743"></span><span class="anchor" id="line-1744"></span><span class="anchor" id="line-1745"></span><span class="anchor" id="line-1746"></span><span class="anchor" id="line-1747"></span><span class="anchor" id="line-1748"></span><span class="anchor" id="line-1749"></span><span class="anchor" id="line-1750"></span><span class="anchor" id="line-1751"></span><span class="anchor" id="line-1752"></span><span class="anchor" id="line-1753"></span><span class="anchor" id="line-1754"></span><span class="anchor" id="line-1755"></span><span class="anchor" id="line-1756"></span><span class="anchor" id="line-1757"></span><span class="anchor" id="line-1758"></span><span class="anchor" id="line-1759"></span><span class="anchor" id="line-1760"></span><span class="anchor" id="line-1761"></span><span class="anchor" id="line-1762"></span><span class="anchor" id="line-1763"></span><span class="anchor" id="line-1764"></span><span class="anchor" id="line-1765"></span><span class="anchor" id="line-1766"></span><span class="anchor" id="line-1767"></span><span class="anchor" id="line-1768"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-d62e324c15377bb102d319779dad4f810781b424\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-d62e324c15377bb102d319779dad4f810781b424', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-d62e324c15377bb102d319779dad4f810781b424" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># commondialogs.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span><span class="ResWord">import</span> <span class="ID">os</span><span class="Operator">,</span> <span class="ID">sys</span></span>
<span class="line"><span class="LineNumber">   7 </span></span>
<span class="line"><span class="LineNumber">   8 </span><span class="ResWord">class</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  10 </span>      <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  11 </span></span>
<span class="line"><span class="LineNumber">  12 </span>      <span class="ID">self</span><span class="Operator">.</span><span class="ID">CreateStatusBar</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span>      <span class="ID">menuBar</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MenuBar</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>      <span class="ID">menu</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Menu</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span>      <span class="ID">menu</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="Number">99</span><span class="Operator">,</span>  <span class="String">"&amp;Message Dialog"</span><span class="Operator">,</span> <span class="String">"Shows a Message Dialog"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span>      <span class="ID">menu</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="Number">100</span><span class="Operator">,</span> <span class="String">"&amp;Color Dialog"</span><span class="Operator">,</span> <span class="String">"Shows a Color Dialog"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span>      <span class="ID">menu</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="Number">101</span><span class="Operator">,</span> <span class="String">"&amp;File Dialog"</span><span class="Operator">,</span> <span class="String">"Shows a File Dialog"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  18 </span>      <span class="ID">menu</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="Number">102</span><span class="Operator">,</span> <span class="String">"&amp;Page Setup Dialog"</span><span class="Operator">,</span> <span class="String">"Shows a Page Setup Dialog"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  19 </span>      <span class="ID">menu</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="Number">103</span><span class="Operator">,</span> <span class="String">"&amp;Font Dialog"</span><span class="Operator">,</span> <span class="String">"Shows a Font Dialog"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  20 </span>      <span class="ID">menu</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="Number">104</span><span class="Operator">,</span> <span class="String">"&amp;Directory Dialog"</span><span class="Operator">,</span> <span class="String">"Shows a Directory Dialog"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  21 </span>      <span class="ID">menu</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="Number">105</span><span class="Operator">,</span> <span class="String">"&amp;SingleChoice Dialog"</span><span class="Operator">,</span> <span class="String">"Shows a SingleChoice Dialog"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  22 </span>      <span class="ID">menu</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="Number">106</span><span class="Operator">,</span> <span class="String">"&amp;TextEntry Dialog"</span><span class="Operator">,</span> <span class="String">"Shows a TextEntry Dialog"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  23 </span>      <span class="ID">menuBar</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="ID">menu</span><span class="Operator">,</span> <span class="String">"&amp;Dialogs"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  24 </span>      <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetMenuBar</span><span class="Operator">(</span><span class="ID">menuBar</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  25 </span></span>
<span class="line"><span class="LineNumber">  26 </span>      <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_MENU</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">message</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">99</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  27 </span>      <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_MENU</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">choosecolor</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">100</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  28 </span>      <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_MENU</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">openfile</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">101</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  29 </span>      <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_MENU</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">pagesetup</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">102</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  30 </span>      <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_MENU</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">choosefont</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">103</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  31 </span>      <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_MENU</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">opendir</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">104</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  32 </span>      <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_MENU</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">singlechoice</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">105</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  33 </span>      <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_MENU</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">textentry</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">106</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  34 </span></span>
<span class="line"><span class="LineNumber">  35 </span>    <span class="ResWord">def</span> <span class="ID">message</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  36 </span>        <span class="ID">dlg</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MessageDialog</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="String">'To save one life is as if you have saved the world.'</span><span class="Operator">,</span> <span class="String">'Talmud'</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">OK</span><span class="Operator">|</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">ICON_INFORMATION</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  37 </span>        <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">ShowModal</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  38 </span>        <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">Destroy</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  39 </span></span>
<span class="line"><span class="LineNumber">  40 </span>    <span class="ResWord">def</span> <span class="ID">choosecolor</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  41 </span>        <span class="ID">dlg</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ColourDialog</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  42 </span>        <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">GetColourData</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">.</span><span class="ID">SetChooseFull</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  43 </span>        <span class="ResWord">if</span> <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">ShowModal</span><span class="Operator">(</span><span class="Operator">)</span> <span class="Operator">==</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ID_OK</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  44 </span>            <span class="ID">data</span> <span class="Operator">=</span> <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">GetColourData</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  45 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetStatusText</span><span class="Operator">(</span><span class="String">'You selected: %s\n'</span> <span class="Operator">%</span> <span class="ID">str</span><span class="Operator">(</span><span class="ID">data</span><span class="Operator">.</span><span class="ID">GetColour</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">.</span><span class="ID">Get</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  46 </span>        <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">Destroy</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  47 </span></span>
<span class="line"><span class="LineNumber">  48 </span>    <span class="ResWord">def</span> <span class="ID">openfile</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  49 </span>       <span class="ID">dlg</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">FileDialog</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="String">"Choose a file"</span><span class="Operator">,</span> <span class="ID">os</span><span class="Operator">.</span><span class="ID">getcwd</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">,</span> <span class="String">""</span><span class="Operator">,</span> <span class="String">"*.*"</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">OPEN</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  50 </span>       <span class="ResWord">if</span> <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">ShowModal</span><span class="Operator">(</span><span class="Operator">)</span> <span class="Operator">==</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ID_OK</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  51 </span>                <span class="ID">path</span> <span class="Operator">=</span> <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">GetPath</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  52 </span>                <span class="ID">mypath</span> <span class="Operator">=</span> <span class="ID">os</span><span class="Operator">.</span><span class="ID">path</span><span class="Operator">.</span><span class="ID">basename</span><span class="Operator">(</span><span class="ID">path</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  53 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetStatusText</span><span class="Operator">(</span><span class="String">"You selected: %s"</span> <span class="Operator">%</span> <span class="ID">mypath</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  54 </span>       <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">Destroy</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  55 </span></span>
<span class="line"><span class="LineNumber">  56 </span>    <span class="ResWord">def</span> <span class="ID">pagesetup</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  57 </span>        <span class="ID">dlg</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">PageSetupDialog</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  58 </span>        <span class="ResWord">if</span> <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">ShowModal</span><span class="Operator">(</span><span class="Operator">)</span> <span class="Operator">==</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ID_OK</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  59 </span>            <span class="ID">data</span> <span class="Operator">=</span> <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">GetPageSetupData</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  60 </span>            <span class="ID">tl</span> <span class="Operator">=</span> <span class="ID">data</span><span class="Operator">.</span><span class="ID">GetMarginTopLeft</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  61 </span>            <span class="ID">br</span> <span class="Operator">=</span> <span class="ID">data</span><span class="Operator">.</span><span class="ID">GetMarginBottomRight</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  62 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetStatusText</span><span class="Operator">(</span><span class="String">'Margins are: %s %s'</span> <span class="Operator">%</span> <span class="Operator">(</span><span class="ID">str</span><span class="Operator">(</span><span class="ID">tl</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">str</span><span class="Operator">(</span><span class="ID">br</span><span class="Operator">)</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  63 </span>        <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">Destroy</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  64 </span></span>
<span class="line"><span class="LineNumber">  65 </span>    <span class="ResWord">def</span> <span class="ID">choosefont</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  66 </span>        <span class="ID">default_font</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Font</span><span class="Operator">(</span><span class="Number">10</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">SWISS</span> <span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">NORMAL</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">NORMAL</span><span class="Operator">,</span> <span class="ID">False</span><span class="Operator">,</span> <span class="String">"Verdana"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  67 </span>        <span class="ID">data</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">FontData</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  68 </span>        <span class="ResWord">if</span> <span class="ID">sys</span><span class="Operator">.</span><span class="ID">platform</span> <span class="Operator">==</span> <span class="String">'win32'</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  69 </span>            <span class="ID">data</span><span class="Operator">.</span><span class="ID">EnableEffects</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  70 </span>        <span class="ID">data</span><span class="Operator">.</span><span class="ID">SetAllowSymbols</span><span class="Operator">(</span><span class="ID">False</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  71 </span>        <span class="ID">data</span><span class="Operator">.</span><span class="ID">SetInitialFont</span><span class="Operator">(</span><span class="ID">default_font</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  72 </span>        <span class="ID">data</span><span class="Operator">.</span><span class="ID">SetRange</span><span class="Operator">(</span><span class="Number">10</span><span class="Operator">,</span> <span class="Number">30</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  73 </span>        <span class="ID">dlg</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">FontDialog</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">data</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  74 </span>        <span class="ResWord">if</span> <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">ShowModal</span><span class="Operator">(</span><span class="Operator">)</span> <span class="Operator">==</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ID_OK</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  75 </span>            <span class="ID">data</span> <span class="Operator">=</span> <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">GetFontData</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  76 </span>            <span class="ID">font</span> <span class="Operator">=</span> <span class="ID">data</span><span class="Operator">.</span><span class="ID">GetChosenFont</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  77 </span>            <span class="ID">color</span> <span class="Operator">=</span> <span class="ID">data</span><span class="Operator">.</span><span class="ID">GetColour</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  78 </span>            <span class="ID">text</span> <span class="Operator">=</span> <span class="String">'Face: %s, Size: %d, Color: %s'</span> <span class="Operator">%</span> <span class="Operator">(</span><span class="ID">font</span><span class="Operator">.</span><span class="ID">GetFaceName</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">font</span><span class="Operator">.</span><span class="ID">GetPointSize</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">,</span>  <span class="ID">color</span><span class="Operator">.</span><span class="ID">Get</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  79 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetStatusText</span><span class="Operator">(</span><span class="ID">text</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  80 </span>        <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">Destroy</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  81 </span></span>
<span class="line"><span class="LineNumber">  82 </span>    <span class="ResWord">def</span> <span class="ID">opendir</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  83 </span>        <span class="ID">dlg</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">DirDialog</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="String">"Choose a directory:"</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">DD_DEFAULT_STYLE</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">DD_NEW_DIR_BUTTON</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  84 </span>        <span class="ResWord">if</span> <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">ShowModal</span><span class="Operator">(</span><span class="Operator">)</span> <span class="Operator">==</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ID_OK</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  85 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetStatusText</span><span class="Operator">(</span><span class="String">'You selected: %s\n'</span> <span class="Operator">%</span> <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">GetPath</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  86 </span>        <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">Destroy</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  87 </span></span>
<span class="line"><span class="LineNumber">  88 </span>    <span class="ResWord">def</span> <span class="ID">singlechoice</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  89 </span>        <span class="ID">sins</span> <span class="Operator">=</span> <span class="Operator">[</span><span class="String">'Greed'</span><span class="Operator">,</span> <span class="String">'Lust'</span><span class="Operator">,</span> <span class="String">'Gluttony'</span><span class="Operator">,</span> <span class="String">'Pride'</span><span class="Operator">,</span> <span class="String">'Sloth'</span><span class="Operator">,</span> <span class="String">'Envy'</span><span class="Operator">,</span> <span class="String">'Wrath'</span><span class="Operator">]</span></span>
<span class="line"><span class="LineNumber">  90 </span>        <span class="ID">dlg</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">SingleChoiceDialog</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="String">'Seven deadly sins'</span><span class="Operator">,</span> <span class="String">'Which one?'</span><span class="Operator">,</span> <span class="ID">sins</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">CHOICEDLG_STYLE</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  91 </span>        <span class="ResWord">if</span> <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">ShowModal</span><span class="Operator">(</span><span class="Operator">)</span> <span class="Operator">==</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ID_OK</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  92 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetStatusText</span><span class="Operator">(</span><span class="String">'You chose: %s\n'</span> <span class="Operator">%</span> <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">GetStringSelection</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  93 </span>        <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">Destroy</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  94 </span></span>
<span class="line"><span class="LineNumber">  95 </span>    <span class="ResWord">def</span> <span class="ID">textentry</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  96 </span>        <span class="ID">dlg</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TextEntryDialog</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="String">'Enter some text'</span><span class="Operator">,</span><span class="String">'Text Entry'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  97 </span>        <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">SetValue</span><span class="Operator">(</span><span class="String">"Default"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  98 </span>        <span class="ResWord">if</span> <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">ShowModal</span><span class="Operator">(</span><span class="Operator">)</span> <span class="Operator">==</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ID_OK</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  99 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetStatusText</span><span class="Operator">(</span><span class="String">'You entered: %s\n'</span> <span class="Operator">%</span> <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">GetValue</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 100 </span>        <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">Destroy</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 101 </span></span>
<span class="line"><span class="LineNumber"> 102 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 103 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 104 </span>        <span class="ID">myframe</span> <span class="Operator">=</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">"commondialogs.py"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 105 </span>        <span class="ID">myframe</span><span class="Operator">.</span><span class="ID">CenterOnScreen</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 106 </span>        <span class="ID">myframe</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 107 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber"> 108 </span></span>
<span class="line"><span class="LineNumber"> 109 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 110 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-1769"></span><p class="line874">The script shows eight different common dialogs. All the output is displayed on the statusbar. <span class="anchor" id="line-1770"></span><span class="anchor" id="line-1771"></span></p><p class="line867"><img alt="messagedialog.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_032.png" title="messagedialog.png">  <img alt="textentrydialog.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_018.png" title="textentrydialog.png"> <br>
 <br>
 <img alt="fontdialog.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_025.png" title="fontdialog.png"> <img alt="colordialog.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_020.png" title="colordialog.png"> <br>
 <br>
 <img alt="directorydialog.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_026.png" title="directorydialog.png"> <img alt="filedialog.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_008.png" title="filedialog.png"> <br>
 <br>
 <img alt="pagesetupdialog.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_004.png" title="pagesetupdialog.png"> <img alt="singlechoicedialog.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_027.png" title="singlechoicedialog.png"> <span class="anchor" id="line-1772"></span><span class="anchor" id="line-1773"></span></p><p class="line867">
</p><h2 id="Core_Widgets">Core Widgets</h2>
<span class="anchor" id="line-1774"></span><p class="line874">In this section, we will introduce basic widgets in wxPython. Each widget will have a small code example. <span class="anchor" id="line-1775"></span><span class="anchor" id="line-1776"></span></p><p class="line867">
</p><h3 id="wx.Button">wx.Button</h3>
<span class="anchor" id="line-1777"></span><p class="line867"><tt>wx.Button</tt> is a simple widget. It contains a text string. It is used to trigger an action. <span class="anchor" id="line-1778"></span><span class="anchor" id="line-1779"></span></p><p class="line867"><strong><tt>wx.Button&nbsp;styles</tt></strong> <span class="anchor" id="line-1780"></span><span class="anchor" id="line-1781"></span></p><ul><li>wx.BU_LEFT <span class="anchor" id="line-1782"></span></li><li>wx.BU_TOP <span class="anchor" id="line-1783"></span></li><li>wx.BU_RIGHT <span class="anchor" id="line-1784"></span></li><li>wx.BU_BOTTOM <span class="anchor" id="line-1785"></span></li><li>wx.BU_EXACTFIT <span class="anchor" id="line-1786"></span></li><li>wx.NO_BORDER <span class="anchor" id="line-1787"></span><span class="anchor" id="line-1788"></span></li></ul><div><table><tbody><tr>  <td colspan="2" style="text-align: center;"><p class="line891"><strong><tt>wx.Button&nbsp;methods</tt></strong> </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-1789"></span><p class="line891"><tt>SetDefault()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">set the button to be the default item on a window </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-1790"></span><p class="line891"><tt>wx.Size&nbsp;GetDefaultSize()</tt> </p></td>
  <td><p class="line862">get the default button size on a platform </p></td>
</tr>
</tbody></table></div><span class="anchor" id="line-1791"></span><span class="anchor" id="line-1792"></span><span class="anchor" id="line-1793"></span><p class="line867"><span class="anchor" id="line-1794"></span><span class="anchor" id="line-1795"></span><span class="anchor" id="line-1796"></span><span class="anchor" id="line-1797"></span><span class="anchor" id="line-1798"></span><span class="anchor" id="line-1799"></span><span class="anchor" id="line-1800"></span><span class="anchor" id="line-1801"></span><span class="anchor" id="line-1802"></span><span class="anchor" id="line-1803"></span><span class="anchor" id="line-1804"></span><span class="anchor" id="line-1805"></span><span class="anchor" id="line-1806"></span><span class="anchor" id="line-1807"></span><span class="anchor" id="line-1808"></span><span class="anchor" id="line-1809"></span><span class="anchor" id="line-1810"></span><span class="anchor" id="line-1811"></span><span class="anchor" id="line-1812"></span><span class="anchor" id="line-1813"></span><span class="anchor" id="line-1814"></span><span class="anchor" id="line-1815"></span><span class="anchor" id="line-1816"></span><span class="anchor" id="line-1817"></span><span class="anchor" id="line-1818"></span><span class="anchor" id="line-1819"></span><span class="anchor" id="line-1820"></span><span class="anchor" id="line-1821"></span><span class="anchor" id="line-1822"></span><span class="anchor" id="line-1823"></span><span class="anchor" id="line-1824"></span><span class="anchor" id="line-1825"></span><span class="anchor" id="line-1826"></span><span class="anchor" id="line-1827"></span><span class="anchor" id="line-1828"></span><span class="anchor" id="line-1829"></span><span class="anchor" id="line-1830"></span><span class="anchor" id="line-1831"></span><span class="anchor" id="line-1832"></span><span class="anchor" id="line-1833"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-37e1895eaf9539c2b581966f328020ec60ca3be6\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-37e1895eaf9539c2b581966f328020ec60ca3be6', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-37e1895eaf9539c2b581966f328020ec60ca3be6" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># buttons.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span><span class="ResWord">import</span> <span class="ID">random</span></span>
<span class="line"><span class="LineNumber">   7 </span></span>
<span class="line"><span class="LineNumber">   8 </span><span class="ID">APP_SIZE_X</span> <span class="Operator">=</span> <span class="Number">300</span></span>
<span class="line"><span class="LineNumber">   9 </span><span class="ID">APP_SIZE_Y</span> <span class="Operator">=</span> <span class="Number">200</span></span>
<span class="line"><span class="LineNumber">  10 </span></span>
<span class="line"><span class="LineNumber">  11 </span><span class="ResWord">class</span> <span class="ID">MyButtons</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Dialog</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  12 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Dialog</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">=</span><span class="Operator">(</span><span class="ID">APP_SIZE_X</span><span class="Operator">,</span> <span class="ID">APP_SIZE_Y</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="String">'Close'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">50</span><span class="Operator">,</span> <span class="Number">130</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">2</span><span class="Operator">,</span> <span class="String">'Random Move'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">150</span><span class="Operator">,</span> <span class="Number">130</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">110</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span></span>
<span class="line"><span class="LineNumber">  18 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnClose</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  19 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnRandomMove</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">2</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  20 </span></span>
<span class="line"><span class="LineNumber">  21 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  22 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">ShowModal</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  23 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Destroy</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  24 </span></span>
<span class="line"><span class="LineNumber">  25 </span>    <span class="ResWord">def</span> <span class="ID">OnClose</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  26 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Close</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  27 </span></span>
<span class="line"><span class="LineNumber">  28 </span>    <span class="ResWord">def</span> <span class="ID">OnRandomMove</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  29 </span>        <span class="ID">screensize</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">GetDisplaySize</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  30 </span>        <span class="ID">randx</span> <span class="Operator">=</span> <span class="ID">random</span><span class="Operator">.</span><span class="ID">randrange</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">,</span> <span class="ID">screensize</span><span class="Operator">.</span><span class="ID">x</span> <span class="Operator">-</span> <span class="ID">APP_SIZE_X</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  31 </span>        <span class="ID">randy</span> <span class="Operator">=</span> <span class="ID">random</span><span class="Operator">.</span><span class="ID">randrange</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">,</span> <span class="ID">screensize</span><span class="Operator">.</span><span class="ID">y</span> <span class="Operator">-</span> <span class="ID">APP_SIZE_Y</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  32 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Move</span><span class="Operator">(</span><span class="Operator">(</span><span class="ID">randx</span><span class="Operator">,</span> <span class="ID">randy</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  33 </span></span>
<span class="line"><span class="LineNumber">  34 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  35 </span><span class="ID">MyButtons</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'buttons.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  36 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-1834"></span><p class="line867"><img alt="buttons.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_028.png" title="buttons.png"> <span class="anchor" id="line-1835"></span><span class="anchor" id="line-1836"></span></p><p class="line867"><strong>Figure: buttons.py</strong> <span class="anchor" id="line-1837"></span><span class="anchor" id="line-1838"></span></p><p class="line867">
</p><h3 id="wx.ToggleButton">wx.ToggleButton</h3>
<span class="anchor" id="line-1839"></span><p class="line867"><tt>wx.ToggleButton</tt>
 is a button that has two states. Pressed and not pressed. You toggle 
between these two states  by clicking on it. There are situations where 
this functionality fits well. <span class="anchor" id="line-1840"></span></p><div><table><tbody><tr>  <td colspan="2" style="text-align: center;"><p class="line891"><strong><tt>wx.ToggleButton&nbsp;methods</tt></strong> </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-1841"></span><p class="line891"><tt>SetValue(bool&nbsp;value)</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">set a state of a toggle button</p></td>
</tr>
<tr>  <td><span class="anchor" id="line-1842"></span><p class="line891"><tt>bool&nbsp;GetValue()</tt> </p></td>
  <td><p class="line862">get a state of the toggle button</p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-1843"></span><p class="line891"><tt>SetLabel(string&nbsp;label)</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">set a label for the button</p></td>
</tr>
</tbody></table></div><span class="anchor" id="line-1844"></span><span class="anchor" id="line-1845"></span><span class="anchor" id="line-1846"></span><span class="anchor" id="line-1847"></span><span class="anchor" id="line-1848"></span><p class="line867"><span class="anchor" id="line-1849"></span><span class="anchor" id="line-1850"></span><span class="anchor" id="line-1851"></span><span class="anchor" id="line-1852"></span><span class="anchor" id="line-1853"></span><span class="anchor" id="line-1854"></span><span class="anchor" id="line-1855"></span><span class="anchor" id="line-1856"></span><span class="anchor" id="line-1857"></span><span class="anchor" id="line-1858"></span><span class="anchor" id="line-1859"></span><span class="anchor" id="line-1860"></span><span class="anchor" id="line-1861"></span><span class="anchor" id="line-1862"></span><span class="anchor" id="line-1863"></span><span class="anchor" id="line-1864"></span><span class="anchor" id="line-1865"></span><span class="anchor" id="line-1866"></span><span class="anchor" id="line-1867"></span><span class="anchor" id="line-1868"></span><span class="anchor" id="line-1869"></span><span class="anchor" id="line-1870"></span><span class="anchor" id="line-1871"></span><span class="anchor" id="line-1872"></span><span class="anchor" id="line-1873"></span><span class="anchor" id="line-1874"></span><span class="anchor" id="line-1875"></span><span class="anchor" id="line-1876"></span><span class="anchor" id="line-1877"></span><span class="anchor" id="line-1878"></span><span class="anchor" id="line-1879"></span><span class="anchor" id="line-1880"></span><span class="anchor" id="line-1881"></span><span class="anchor" id="line-1882"></span><span class="anchor" id="line-1883"></span><span class="anchor" id="line-1884"></span><span class="anchor" id="line-1885"></span><span class="anchor" id="line-1886"></span><span class="anchor" id="line-1887"></span><span class="anchor" id="line-1888"></span><span class="anchor" id="line-1889"></span><span class="anchor" id="line-1890"></span><span class="anchor" id="line-1891"></span><span class="anchor" id="line-1892"></span><span class="anchor" id="line-1893"></span><span class="anchor" id="line-1894"></span><span class="anchor" id="line-1895"></span><span class="anchor" id="line-1896"></span><span class="anchor" id="line-1897"></span><span class="anchor" id="line-1898"></span><span class="anchor" id="line-1899"></span><span class="anchor" id="line-1900"></span><span class="anchor" id="line-1901"></span><span class="anchor" id="line-1902"></span><span class="anchor" id="line-1903"></span><span class="anchor" id="line-1904"></span><span class="anchor" id="line-1905"></span><span class="anchor" id="line-1906"></span><span class="anchor" id="line-1907"></span><span class="anchor" id="line-1908"></span><span class="anchor" id="line-1909"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-13417752c81b4817679e91a6430ca7cbca62b2ee\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-13417752c81b4817679e91a6430ca7cbca62b2ee', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-13417752c81b4817679e91a6430ca7cbca62b2ee" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># togglebuttons.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ResWord">class</span> <span class="ID">ToggleButtons</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Dialog</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   8 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Dialog</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">300</span><span class="Operator">,</span> <span class="Number">200</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  10 </span></span>
<span class="line"><span class="LineNumber">  11 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">colour</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Colour</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  12 </span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ToggleButton</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="String">'red'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">20</span><span class="Operator">,</span> <span class="Number">25</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ToggleButton</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">2</span><span class="Operator">,</span> <span class="String">'green'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">20</span><span class="Operator">,</span> <span class="Number">60</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ToggleButton</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">3</span><span class="Operator">,</span> <span class="String">'blue'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">20</span><span class="Operator">,</span> <span class="Number">100</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">panel</span>  <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">150</span><span class="Operator">,</span> <span class="Number">20</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">110</span><span class="Operator">,</span> <span class="Number">110</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">SUNKEN_BORDER</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  18 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">panel</span><span class="Operator">.</span><span class="ID">SetBackgroundColour</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">colour</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  19 </span></span>
<span class="line"><span class="LineNumber">  20 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_TOGGLEBUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">ToggleRed</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  21 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_TOGGLEBUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">ToggleGreen</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">2</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  22 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_TOGGLEBUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">ToggleBlue</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">3</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  23 </span></span>
<span class="line"><span class="LineNumber">  24 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  25 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">ShowModal</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  26 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Destroy</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  27 </span></span>
<span class="line"><span class="LineNumber">  28 </span>    <span class="ResWord">def</span> <span class="ID">ToggleRed</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  29 </span>        <span class="ID">green</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">colour</span><span class="Operator">.</span><span class="ID">Green</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  30 </span>        <span class="ID">blue</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">colour</span><span class="Operator">.</span><span class="ID">Blue</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  31 </span>        <span class="ResWord">if</span>  <span class="ID">self</span><span class="Operator">.</span><span class="ID">colour</span><span class="Operator">.</span><span class="ID">Red</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  32 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">colour</span><span class="Operator">.</span><span class="ID">Set</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">,</span> <span class="ID">green</span><span class="Operator">,</span> <span class="ID">blue</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  33 </span>        <span class="ResWord">else</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  34 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">colour</span><span class="Operator">.</span><span class="ID">Set</span><span class="Operator">(</span><span class="Number">255</span><span class="Operator">,</span> <span class="ID">green</span><span class="Operator">,</span> <span class="ID">blue</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  35 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">panel</span><span class="Operator">.</span><span class="ID">SetBackgroundColour</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">colour</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  36 </span></span>
<span class="line"><span class="LineNumber">  37 </span>    <span class="ResWord">def</span> <span class="ID">ToggleGreen</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  38 </span>        <span class="ID">red</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">colour</span><span class="Operator">.</span><span class="ID">Red</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  39 </span>        <span class="ID">blue</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">colour</span><span class="Operator">.</span><span class="ID">Blue</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  40 </span>        <span class="ResWord">if</span>  <span class="ID">self</span><span class="Operator">.</span><span class="ID">colour</span><span class="Operator">.</span><span class="ID">Green</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  41 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">colour</span><span class="Operator">.</span><span class="ID">Set</span><span class="Operator">(</span><span class="ID">red</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">blue</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  42 </span>        <span class="ResWord">else</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  43 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">colour</span><span class="Operator">.</span><span class="ID">Set</span><span class="Operator">(</span><span class="ID">red</span><span class="Operator">,</span> <span class="Number">255</span><span class="Operator">,</span> <span class="ID">blue</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  44 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">panel</span><span class="Operator">.</span><span class="ID">SetBackgroundColour</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">colour</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  45 </span></span>
<span class="line"><span class="LineNumber">  46 </span>    <span class="ResWord">def</span> <span class="ID">ToggleBlue</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  47 </span>        <span class="ID">red</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">colour</span><span class="Operator">.</span><span class="ID">Red</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  48 </span>        <span class="ID">green</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">colour</span><span class="Operator">.</span><span class="ID">Green</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  49 </span>        <span class="ResWord">if</span>  <span class="ID">self</span><span class="Operator">.</span><span class="ID">colour</span><span class="Operator">.</span><span class="ID">Blue</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  50 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">colour</span><span class="Operator">.</span><span class="ID">Set</span><span class="Operator">(</span><span class="ID">red</span><span class="Operator">,</span> <span class="ID">green</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  51 </span>        <span class="ResWord">else</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  52 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">colour</span><span class="Operator">.</span><span class="ID">Set</span><span class="Operator">(</span><span class="ID">red</span><span class="Operator">,</span> <span class="ID">green</span><span class="Operator">,</span> <span class="Number">255</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  53 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">panel</span><span class="Operator">.</span><span class="ID">SetBackgroundColour</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">colour</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  54 </span></span>
<span class="line"><span class="LineNumber">  55 </span></span>
<span class="line"><span class="LineNumber">  56 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  57 </span><span class="ID">ToggleButtons</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'togglebuttons.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  58 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-1910"></span><p class="line867"><img alt="togglebuttons.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_042.png" title="togglebuttons.png"> <span class="anchor" id="line-1911"></span><span class="anchor" id="line-1912"></span></p><p class="line867"><strong>Figure: togglebuttons.py</strong> <span class="anchor" id="line-1913"></span><span class="anchor" id="line-1914"></span></p><p class="line867">
</p><h3 id="wx.BitmapButton">wx.BitmapButton</h3>
<span class="anchor" id="line-1915"></span><p class="line874">A bitmap 
button is a button, that displays a bitmap. A bitmap button can have 
three other states. Selected, focused and displayed. We can set a 
specific bitmap for those states. <span class="anchor" id="line-1916"></span></p><div><table><tbody><tr>  <td colspan="2" style="text-align: center;"><p class="line891"><strong><tt>wx.BitmapButton&nbsp;methods</tt></strong> </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-1917"></span><p class="line891"><tt>wx.Bitmap&nbsp;GetBitmapLabel()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">return the label bitmap</p></td>
</tr>
<tr>  <td><span class="anchor" id="line-1918"></span><p class="line891"><tt>SetBitmapLabel(wx.Bitmap&nbsp;bitmap)</tt> </p></td>
  <td><p class="line862">set the bitmap label for the button</p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-1919"></span><p class="line891"><tt>wx.Bitmap&nbsp;GetBitmapFocus()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">return the bitmap for the focused state</p></td>
</tr>
<tr>  <td><span class="anchor" id="line-1920"></span><p class="line891"><tt>wx.Bitmap&nbsp;GetBitmapDisabled()</tt> </p></td>
  <td><p class="line862">return the bitmap for the disabled state</p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-1921"></span><p class="line891"><tt>wx.Bitmap&nbsp;GetBitmapSelected()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">return the bitmap for the selected state</p></td>
</tr>
<tr>  <td><span class="anchor" id="line-1922"></span><p class="line891"><tt>SetBitmapFocus(wx.Bitmap&nbsp;bitmap)</tt> </p></td>
  <td><p class="line862">set the bitmap for the focused state</p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-1923"></span><p class="line891"><tt>SetBitmapSelected(wx.Bitmap&nbsp;bitmap)</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">set the bitmap for the selected state</p></td>
</tr>
<tr>  <td><span class="anchor" id="line-1924"></span><p class="line891"><tt>SetBitmapDisabled(wx.Bitmap&nbsp;bitmap)</tt> </p></td>
  <td><p class="line862">set the bitmap for the disabled state</p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-1925"></span><p class="line891"><tt>SetMargins(int&nbsp;x,&nbsp;int&nbsp;y)</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">not implemented</p></td>
</tr>
<tr>  <td><span class="anchor" id="line-1926"></span><p class="line891"><tt>int&nbsp;GetMarginX()</tt> </p></td>
  <td><p class="line862">not implemented</p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-1927"></span><p class="line891"><tt>int&nbsp;GetMarginY()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">not implemented</p></td>
</tr>
</tbody></table></div><span class="anchor" id="line-1928"></span><span class="anchor" id="line-1929"></span><span class="anchor" id="line-1930"></span><span class="anchor" id="line-1931"></span><span class="anchor" id="line-1932"></span><p class="line874">A
 video player is a nice example, where bitmap buttons are used. We can 
see play, pause, next, previous and volume bitmap buttons there. So we 
create a skeleton of a video player in our next example. <span class="anchor" id="line-1933"></span><span class="anchor" id="line-1934"></span></p><p class="line867"><span class="anchor" id="line-1935"></span><span class="anchor" id="line-1936"></span><span class="anchor" id="line-1937"></span><span class="anchor" id="line-1938"></span><span class="anchor" id="line-1939"></span><span class="anchor" id="line-1940"></span><span class="anchor" id="line-1941"></span><span class="anchor" id="line-1942"></span><span class="anchor" id="line-1943"></span><span class="anchor" id="line-1944"></span><span class="anchor" id="line-1945"></span><span class="anchor" id="line-1946"></span><span class="anchor" id="line-1947"></span><span class="anchor" id="line-1948"></span><span class="anchor" id="line-1949"></span><span class="anchor" id="line-1950"></span><span class="anchor" id="line-1951"></span><span class="anchor" id="line-1952"></span><span class="anchor" id="line-1953"></span><span class="anchor" id="line-1954"></span><span class="anchor" id="line-1955"></span><span class="anchor" id="line-1956"></span><span class="anchor" id="line-1957"></span><span class="anchor" id="line-1958"></span><span class="anchor" id="line-1959"></span><span class="anchor" id="line-1960"></span><span class="anchor" id="line-1961"></span><span class="anchor" id="line-1962"></span><span class="anchor" id="line-1963"></span><span class="anchor" id="line-1964"></span><span class="anchor" id="line-1965"></span><span class="anchor" id="line-1966"></span><span class="anchor" id="line-1967"></span><span class="anchor" id="line-1968"></span><span class="anchor" id="line-1969"></span><span class="anchor" id="line-1970"></span><span class="anchor" id="line-1971"></span><span class="anchor" id="line-1972"></span><span class="anchor" id="line-1973"></span><span class="anchor" id="line-1974"></span><span class="anchor" id="line-1975"></span><span class="anchor" id="line-1976"></span><span class="anchor" id="line-1977"></span><span class="anchor" id="line-1978"></span><span class="anchor" id="line-1979"></span><span class="anchor" id="line-1980"></span><span class="anchor" id="line-1981"></span><span class="anchor" id="line-1982"></span><span class="anchor" id="line-1983"></span><span class="anchor" id="line-1984"></span><span class="anchor" id="line-1985"></span><span class="anchor" id="line-1986"></span><span class="anchor" id="line-1987"></span><span class="anchor" id="line-1988"></span><span class="anchor" id="line-1989"></span><span class="anchor" id="line-1990"></span><span class="anchor" id="line-1991"></span><span class="anchor" id="line-1992"></span><span class="anchor" id="line-1993"></span><span class="anchor" id="line-1994"></span><span class="anchor" id="line-1995"></span><span class="anchor" id="line-1996"></span><span class="anchor" id="line-1997"></span><span class="anchor" id="line-1998"></span><span class="anchor" id="line-1999"></span><span class="anchor" id="line-2000"></span><span class="anchor" id="line-2001"></span><span class="anchor" id="line-2002"></span><span class="anchor" id="line-2003"></span><span class="anchor" id="line-2004"></span><span class="anchor" id="line-2005"></span><span class="anchor" id="line-2006"></span><span class="anchor" id="line-2007"></span><span class="anchor" id="line-2008"></span><span class="anchor" id="line-2009"></span><span class="anchor" id="line-2010"></span><span class="anchor" id="line-2011"></span><span class="anchor" id="line-2012"></span><span class="anchor" id="line-2013"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-bce8809381e8acbd60a707925fd089fa701df1c8\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-bce8809381e8acbd60a707925fd089fa701df1c8', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-bce8809381e8acbd60a707925fd089fa701df1c8" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># player.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ResWord">class</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   8 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">350</span><span class="Operator">,</span> <span class="Number">300</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  10 </span>        <span class="ID">panel</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  11 </span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">pnl1</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">pnl1</span><span class="Operator">.</span><span class="ID">SetBackgroundColour</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">BLACK</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">pnl2</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span> <span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span></span>
<span class="line"><span class="LineNumber">  16 </span>        <span class="ID">menubar</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MenuBar</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="ID">file</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Menu</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  18 </span>        <span class="ID">play</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Menu</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  19 </span>        <span class="ID">view</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Menu</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  20 </span>        <span class="ID">tools</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Menu</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  21 </span>        <span class="ID">favorites</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Menu</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  22 </span>        <span class="ID">help</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Menu</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  23 </span></span>
<span class="line"><span class="LineNumber">  24 </span>        <span class="ID">file</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="Number">101</span><span class="Operator">,</span> <span class="String">'&amp;quit'</span><span class="Operator">,</span> <span class="String">'Quit application'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  25 </span></span>
<span class="line"><span class="LineNumber">  26 </span>        <span class="ID">menubar</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="ID">file</span><span class="Operator">,</span> <span class="String">'&amp;File'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  27 </span>        <span class="ID">menubar</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="ID">play</span><span class="Operator">,</span> <span class="String">'&amp;Play'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  28 </span>        <span class="ID">menubar</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="ID">view</span><span class="Operator">,</span> <span class="String">'&amp;View'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  29 </span>        <span class="ID">menubar</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="ID">tools</span><span class="Operator">,</span> <span class="String">'&amp;Tools'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  30 </span>        <span class="ID">menubar</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="ID">favorites</span><span class="Operator">,</span> <span class="String">'F&amp;avorites'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  31 </span>        <span class="ID">menubar</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="ID">help</span><span class="Operator">,</span> <span class="String">'&amp;Help'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  32 </span></span>
<span class="line"><span class="LineNumber">  33 </span>        <span class="ID">slider1</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Slider</span><span class="Operator">(</span><span class="ID">pnl2</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="Number">1000</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  34 </span>        <span class="ID">pause</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BitmapButton</span><span class="Operator">(</span><span class="ID">pnl2</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bitmap</span><span class="Operator">(</span><span class="String">'icons/stock_media-pause.png'</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  35 </span>        <span class="ID">play</span>  <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BitmapButton</span><span class="Operator">(</span><span class="ID">pnl2</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bitmap</span><span class="Operator">(</span><span class="String">'icons/stock_media-play.png'</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  36 </span>        <span class="ID">next</span>  <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BitmapButton</span><span class="Operator">(</span><span class="ID">pnl2</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bitmap</span><span class="Operator">(</span><span class="String">'icons/stock_media-next.png'</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  37 </span>        <span class="ID">prev</span>  <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BitmapButton</span><span class="Operator">(</span><span class="ID">pnl2</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bitmap</span><span class="Operator">(</span><span class="String">'icons/stock_media-prev.png'</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  38 </span>        <span class="ID">volume</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BitmapButton</span><span class="Operator">(</span><span class="ID">pnl2</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bitmap</span><span class="Operator">(</span><span class="String">'icons/volume.png'</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  39 </span>        <span class="ID">slider2</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Slider</span><span class="Operator">(</span><span class="ID">pnl2</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="Number">100</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">120</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  40 </span></span>
<span class="line"><span class="LineNumber">  41 </span>        <span class="ID">vbox</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BoxSizer</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">VERTICAL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  42 </span>        <span class="ID">hbox1</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BoxSizer</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">HORIZONTAL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  43 </span>        <span class="ID">hbox2</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BoxSizer</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">HORIZONTAL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  44 </span></span>
<span class="line"><span class="LineNumber">  45 </span>        <span class="ID">hbox1</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">slider1</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  46 </span>        <span class="ID">hbox2</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">pause</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  47 </span>        <span class="ID">hbox2</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">play</span><span class="Operator">,</span> <span class="ID">flag</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">RIGHT</span><span class="Operator">,</span> <span class="ID">border</span><span class="Operator">=</span><span class="Number">5</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  48 </span>        <span class="ID">hbox2</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">next</span><span class="Operator">,</span> <span class="ID">flag</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">LEFT</span><span class="Operator">,</span> <span class="ID">border</span><span class="Operator">=</span><span class="Number">5</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  49 </span>        <span class="ID">hbox2</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">prev</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  50 </span>        <span class="ID">hbox2</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="Operator">(</span><span class="Number">150</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">flag</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_RIGHT</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  51 </span>        <span class="ID">hbox2</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">volume</span><span class="Operator">,</span> <span class="ID">flag</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_RIGHT</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  52 </span>        <span class="ID">hbox2</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">slider2</span><span class="Operator">,</span> <span class="ID">flag</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_RIGHT</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TOP</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">LEFT</span><span class="Operator">,</span> <span class="ID">border</span><span class="Operator">=</span><span class="Number">5</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  53 </span></span>
<span class="line"><span class="LineNumber">  54 </span>        <span class="ID">vbox</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">hbox1</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BOTTOM</span><span class="Operator">,</span> <span class="Number">10</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  55 </span>        <span class="ID">vbox</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">hbox2</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  56 </span>        <span class="ID">pnl2</span><span class="Operator">.</span><span class="ID">SetSizer</span><span class="Operator">(</span><span class="ID">vbox</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  57 </span></span>
<span class="line"><span class="LineNumber">  58 </span>        <span class="ID">sizer</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BoxSizer</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">VERTICAL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  59 </span>        <span class="ID">sizer</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">pnl1</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">flag</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  60 </span>        <span class="ID">sizer</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">pnl2</span><span class="Operator">,</span> <span class="ID">flag</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BOTTOM</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TOP</span><span class="Operator">,</span> <span class="ID">border</span><span class="Operator">=</span><span class="Number">10</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  61 </span></span>
<span class="line"><span class="LineNumber">  62 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetMinSize</span><span class="Operator">(</span><span class="Operator">(</span><span class="Number">350</span><span class="Operator">,</span> <span class="Number">300</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  63 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetMenuBar</span><span class="Operator">(</span><span class="ID">menubar</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  64 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">CreateStatusBar</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  65 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetSizer</span><span class="Operator">(</span><span class="ID">sizer</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  66 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  67 </span></span>
<span class="line"><span class="LineNumber">  68 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  69 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  70 </span>        <span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Player'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  71 </span>        <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  72 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetTopWindow</span><span class="Operator">(</span><span class="ID">frame</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  73 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  74 </span></span>
<span class="line"><span class="LineNumber">  75 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  76 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-2014"></span><p class="line867"><img alt="player.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial.png" title="player.png"> <span class="anchor" id="line-2015"></span><span class="anchor" id="line-2016"></span></p><p class="line867"><strong>Figure: player.py</strong> <span class="anchor" id="line-2017"></span><span class="anchor" id="line-2018"></span></p><p class="line867">
</p><h3 id="wx.StaticLine">wx.StaticLine</h3>
<span class="anchor" id="line-2019"></span><p class="line874">This widget displays a simple line on the window. It can be horizontal or vertical. <span class="anchor" id="line-2020"></span><span class="anchor" id="line-2021"></span></p><p class="line867"><strong><tt>wx.StaticLine&nbsp;styles</tt></strong> <span class="anchor" id="line-2022"></span><span class="anchor" id="line-2023"></span></p><ul><li>wx.LI_HORIZONTAL <span class="anchor" id="line-2024"></span></li><li>wx.LI_VERTICAL <span class="anchor" id="line-2025"></span><span class="anchor" id="line-2026"></span></li></ul><div><table><tbody><tr>  <td colspan="2" style="text-align: center;"><p class="line891"><strong><tt>wx.StaticLine&nbsp;methods</tt></strong> </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-2027"></span><p class="line891"><tt>bool&nbsp;IsVertical()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">check if the line is vertical </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-2028"></span><p class="line891"><tt>integer&nbsp;GetDefaultSize()</tt> </p></td>
  <td><p class="line862">return the size of the line </p></td>
</tr>
</tbody></table></div><span class="anchor" id="line-2029"></span><span class="anchor" id="line-2030"></span><span class="anchor" id="line-2031"></span><p class="line867"><span class="anchor" id="line-2032"></span><span class="anchor" id="line-2033"></span><span class="anchor" id="line-2034"></span><span class="anchor" id="line-2035"></span><span class="anchor" id="line-2036"></span><span class="anchor" id="line-2037"></span><span class="anchor" id="line-2038"></span><span class="anchor" id="line-2039"></span><span class="anchor" id="line-2040"></span><span class="anchor" id="line-2041"></span><span class="anchor" id="line-2042"></span><span class="anchor" id="line-2043"></span><span class="anchor" id="line-2044"></span><span class="anchor" id="line-2045"></span><span class="anchor" id="line-2046"></span><span class="anchor" id="line-2047"></span><span class="anchor" id="line-2048"></span><span class="anchor" id="line-2049"></span><span class="anchor" id="line-2050"></span><span class="anchor" id="line-2051"></span><span class="anchor" id="line-2052"></span><span class="anchor" id="line-2053"></span><span class="anchor" id="line-2054"></span><span class="anchor" id="line-2055"></span><span class="anchor" id="line-2056"></span><span class="anchor" id="line-2057"></span><span class="anchor" id="line-2058"></span><span class="anchor" id="line-2059"></span><span class="anchor" id="line-2060"></span><span class="anchor" id="line-2061"></span><span class="anchor" id="line-2062"></span><span class="anchor" id="line-2063"></span><span class="anchor" id="line-2064"></span><span class="anchor" id="line-2065"></span><span class="anchor" id="line-2066"></span><span class="anchor" id="line-2067"></span><span class="anchor" id="line-2068"></span><span class="anchor" id="line-2069"></span><span class="anchor" id="line-2070"></span><span class="anchor" id="line-2071"></span><span class="anchor" id="line-2072"></span><span class="anchor" id="line-2073"></span><span class="anchor" id="line-2074"></span><span class="anchor" id="line-2075"></span><span class="anchor" id="line-2076"></span><span class="anchor" id="line-2077"></span><span class="anchor" id="line-2078"></span><span class="anchor" id="line-2079"></span><span class="anchor" id="line-2080"></span><span class="anchor" id="line-2081"></span><span class="anchor" id="line-2082"></span><span class="anchor" id="line-2083"></span><span class="anchor" id="line-2084"></span><span class="anchor" id="line-2085"></span><span class="anchor" id="line-2086"></span><span class="anchor" id="line-2087"></span><span class="anchor" id="line-2088"></span><span class="anchor" id="line-2089"></span><span class="anchor" id="line-2090"></span><span class="anchor" id="line-2091"></span><span class="anchor" id="line-2092"></span><span class="anchor" id="line-2093"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-0ca84827625bfeba6cc0335d8d2de4e1c3472b66\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-0ca84827625bfeba6cc0335d8d2de4e1c3472b66', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-0ca84827625bfeba6cc0335d8d2de4e1c3472b66" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># centraleurope.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ResWord">class</span> <span class="ID">MyDialog</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Dialog</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   8 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span> <span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">ID</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Dialog</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">ID</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">360</span><span class="Operator">,</span> <span class="Number">370</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  10 </span></span>
<span class="line"><span class="LineNumber">  11 </span>        <span class="ID">font</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Font</span><span class="Operator">(</span><span class="Number">10</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">DEFAULT</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">NORMAL</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BOLD</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">heading</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'The Central Europe'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">130</span><span class="Operator">,</span> <span class="Number">15</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">heading</span><span class="Operator">.</span><span class="ID">SetFont</span><span class="Operator">(</span><span class="ID">font</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticLine</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">25</span><span class="Operator">,</span> <span class="Number">50</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">300</span><span class="Operator">,</span><span class="Number">1</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Slovakia'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">25</span><span class="Operator">,</span> <span class="Number">80</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_RIGHT</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  18 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Hungary'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">25</span><span class="Operator">,</span> <span class="Number">100</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_RIGHT</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  19 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Poland'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">25</span><span class="Operator">,</span> <span class="Number">120</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_RIGHT</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  20 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Czech Republic'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">25</span><span class="Operator">,</span> <span class="Number">140</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  21 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Germany'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">25</span><span class="Operator">,</span> <span class="Number">160</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  22 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Slovenia'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">25</span><span class="Operator">,</span> <span class="Number">180</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  23 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Austria'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">25</span><span class="Operator">,</span> <span class="Number">200</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  24 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Switzerland'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">25</span><span class="Operator">,</span> <span class="Number">220</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  25 </span></span>
<span class="line"><span class="LineNumber">  26 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'5 379 000'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">250</span><span class="Operator">,</span> <span class="Number">80</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  27 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'10 084 000'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">250</span><span class="Operator">,</span> <span class="Number">100</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  28 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'38 635 000'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">250</span><span class="Operator">,</span> <span class="Number">120</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  29 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'10 240 000'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">250</span><span class="Operator">,</span> <span class="Number">140</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  30 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'82 443 000'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">250</span><span class="Operator">,</span> <span class="Number">160</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  31 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'2 001 000'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">250</span><span class="Operator">,</span> <span class="Number">180</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  32 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'8 032 000'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">250</span><span class="Operator">,</span> <span class="Number">200</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  33 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'7 288 000'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">250</span><span class="Operator">,</span> <span class="Number">220</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  34 </span></span>
<span class="line"><span class="LineNumber">  35 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticLine</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">25</span><span class="Operator">,</span> <span class="Number">260</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">300</span><span class="Operator">,</span><span class="Number">1</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  36 </span></span>
<span class="line"><span class="LineNumber">  37 </span>        <span class="ID">sum</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'164 102 000'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">240</span><span class="Operator">,</span> <span class="Number">280</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  38 </span>        <span class="ID">sum_font</span> <span class="Operator">=</span> <span class="ID">sum</span><span class="Operator">.</span><span class="ID">GetFont</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  39 </span>        <span class="ID">sum_font</span><span class="Operator">.</span><span class="ID">SetWeight</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">BOLD</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  40 </span>        <span class="ID">sum</span><span class="Operator">.</span><span class="ID">SetFont</span><span class="Operator">(</span><span class="ID">sum_font</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  41 </span></span>
<span class="line"><span class="LineNumber">  42 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="String">'Ok'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">140</span><span class="Operator">,</span> <span class="Number">310</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">60</span><span class="Operator">,</span> <span class="Number">30</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  43 </span></span>
<span class="line"><span class="LineNumber">  44 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnOk</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  45 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  46 </span></span>
<span class="line"><span class="LineNumber">  47 </span>    <span class="ResWord">def</span> <span class="ID">OnOk</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  48 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Close</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  49 </span></span>
<span class="line"><span class="LineNumber">  50 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  51 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  52 </span>        <span class="ID">dia</span> <span class="Operator">=</span> <span class="ID">MyDialog</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'centraleurope.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  53 </span>        <span class="ID">dia</span><span class="Operator">.</span><span class="ID">ShowModal</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  54 </span>        <span class="ID">dia</span><span class="Operator">.</span><span class="ID">Destroy</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  55 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  56 </span></span>
<span class="line"><span class="LineNumber">  57 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  58 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-2094"></span><p class="line862">centraleurope.py script displays central european countries and their population. The<tt>wx.StatLine</tt> makes it look more visually attractive. <span class="anchor" id="line-2095"></span><span class="anchor" id="line-2096"></span></p><p class="line867"><img alt="centraleurope.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_007.png" title="centraleurope.png"> <span class="anchor" id="line-2097"></span><span class="anchor" id="line-2098"></span></p><p class="line867"><strong>Figure: centraleurope.py</strong> <span class="anchor" id="line-2099"></span><span class="anchor" id="line-2100"></span></p><p class="line867">
</p><h3 id="wx.StaticText">wx.StaticText</h3>
<span class="anchor" id="line-2101"></span><p class="line862">A<tt>wx.StaticText</tt> widget displays one or more lines of read-only text. <span class="anchor" id="line-2102"></span><span class="anchor" id="line-2103"></span></p><p class="line867"><strong><tt>wx.StaticText&nbsp;Styles</tt></strong> <span class="anchor" id="line-2104"></span><span class="anchor" id="line-2105"></span></p><ul><li>wx.ALIGN_RIGHT <span class="anchor" id="line-2106"></span></li><li>wx.ALIGN_LEFT <span class="anchor" id="line-2107"></span></li><li>wx.ALIGN_CENTER / wx.ALIGN_CENTRE <span class="anchor" id="line-2108"></span></li><li>wx.ST_NO_AUTORESIZE <span class="anchor" id="line-2109"></span><span class="anchor" id="line-2110"></span></li></ul><div><table><tbody><tr>  <td colspan="2" style="text-align: center;"><p class="line891"><strong><tt>wx.StaticText&nbsp;methods</tt></strong> </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-2111"></span><p class="line891"><tt>Wrap(int&nbsp;width)</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">if possible set each line of text to width pixels. if width is negative, no wrapping is done.</p></td>
</tr>
</tbody></table></div><span class="anchor" id="line-2112"></span><span class="anchor" id="line-2113"></span><span class="anchor" id="line-2114"></span><p class="line867"><span class="anchor" id="line-2115"></span><span class="anchor" id="line-2116"></span><span class="anchor" id="line-2117"></span><span class="anchor" id="line-2118"></span><span class="anchor" id="line-2119"></span><span class="anchor" id="line-2120"></span><span class="anchor" id="line-2121"></span><span class="anchor" id="line-2122"></span><span class="anchor" id="line-2123"></span><span class="anchor" id="line-2124"></span><span class="anchor" id="line-2125"></span><span class="anchor" id="line-2126"></span><span class="anchor" id="line-2127"></span><span class="anchor" id="line-2128"></span><span class="anchor" id="line-2129"></span><span class="anchor" id="line-2130"></span><span class="anchor" id="line-2131"></span><span class="anchor" id="line-2132"></span><span class="anchor" id="line-2133"></span><span class="anchor" id="line-2134"></span><span class="anchor" id="line-2135"></span><span class="anchor" id="line-2136"></span><span class="anchor" id="line-2137"></span><span class="anchor" id="line-2138"></span><span class="anchor" id="line-2139"></span><span class="anchor" id="line-2140"></span><span class="anchor" id="line-2141"></span><span class="anchor" id="line-2142"></span><span class="anchor" id="line-2143"></span><span class="anchor" id="line-2144"></span><span class="anchor" id="line-2145"></span><span class="anchor" id="line-2146"></span><span class="anchor" id="line-2147"></span><span class="anchor" id="line-2148"></span><span class="anchor" id="line-2149"></span><span class="anchor" id="line-2150"></span><span class="anchor" id="line-2151"></span><span class="anchor" id="line-2152"></span><span class="anchor" id="line-2153"></span><span class="anchor" id="line-2154"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-0d3f6d5f9abbb168490e56733b9d7ee06a260aad\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-0d3f6d5f9abbb168490e56733b9d7ee06a260aad', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-0d3f6d5f9abbb168490e56733b9d7ee06a260aad" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># statictext.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ResWord">class</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   8 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">DefaultPosition</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Size</span><span class="Operator">(</span><span class="Number">320</span><span class="Operator">,</span> <span class="Number">350</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  10 </span></span>
<span class="line"><span class="LineNumber">  11 </span>        <span class="ID">lyrics1</span> <span class="Operator">=</span> <span class="String">'''I'm giving up the ghost of love</span></span>
<span class="line"><span class="LineNumber">  12 </span><span class="String">in the shadows cast on devotion</span></span>
<span class="line"><span class="LineNumber">  13 </span><span class="String">She is the one that I adore</span></span>
<span class="line"><span class="LineNumber">  14 </span><span class="String">creed of my silent suffocation</span></span>
<span class="line"><span class="LineNumber">  15 </span><span class="String">Break this bittersweet spell on me</span></span>
<span class="line"><span class="LineNumber">  16 </span><span class="String">lost in the arms of destiny'''</span></span>
<span class="line"><span class="LineNumber">  17 </span></span>
<span class="line"><span class="LineNumber">  18 </span>        <span class="ID">lyrics2</span> <span class="Operator">=</span> <span class="String">'''There is something in the way</span></span>
<span class="line"><span class="LineNumber">  19 </span><span class="String">You're always somewhere else</span></span>
<span class="line"><span class="LineNumber">  20 </span><span class="String">Feelings have deserted me</span></span>
<span class="line"><span class="LineNumber">  21 </span><span class="String">To a point of no return</span></span>
<span class="line"><span class="LineNumber">  22 </span><span class="String">I don't believe in God</span></span>
<span class="line"><span class="LineNumber">  23 </span><span class="String">But I pray for you'''</span></span>
<span class="line"><span class="LineNumber">  24 </span></span>
<span class="line"><span class="LineNumber">  25 </span>        <span class="ID">panel</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  26 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">lyrics1</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">45</span><span class="Operator">,</span> <span class="Number">25</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_CENTRE</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  27 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">lyrics2</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">45</span><span class="Operator">,</span> <span class="Number">190</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_CENTRE</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  28 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  29 </span></span>
<span class="line"><span class="LineNumber">  30 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  31 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  32 </span>        <span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'statictext.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  33 </span>        <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  34 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetTopWindow</span><span class="Operator">(</span><span class="ID">frame</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  35 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  36 </span></span>
<span class="line"><span class="LineNumber">  37 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  38 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-2155"></span><p class="line867"><img alt="statictext.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_021.png" title="statictext.png"> <span class="anchor" id="line-2156"></span><span class="anchor" id="line-2157"></span></p><p class="line867"><strong>Figure statictext.py</strong> <span class="anchor" id="line-2158"></span><span class="anchor" id="line-2159"></span></p><p class="line867">
</p><h3 id="wx.StaticBox">wx.StaticBox</h3>
<span class="anchor" id="line-2160"></span><p class="line874">This is a 
kind of a decorator widget. It is used to logically group various 
widgets.  Note that this widget must be created before the widgets that 
it contains, and that those widgets should be siblings, not children, of
 the static box. <span class="anchor" id="line-2161"></span><span class="anchor" id="line-2162"></span></p><p class="line867"><span class="anchor" id="line-2163"></span><span class="anchor" id="line-2164"></span><span class="anchor" id="line-2165"></span><span class="anchor" id="line-2166"></span><span class="anchor" id="line-2167"></span><span class="anchor" id="line-2168"></span><span class="anchor" id="line-2169"></span><span class="anchor" id="line-2170"></span><span class="anchor" id="line-2171"></span><span class="anchor" id="line-2172"></span><span class="anchor" id="line-2173"></span><span class="anchor" id="line-2174"></span><span class="anchor" id="line-2175"></span><span class="anchor" id="line-2176"></span><span class="anchor" id="line-2177"></span><span class="anchor" id="line-2178"></span><span class="anchor" id="line-2179"></span><span class="anchor" id="line-2180"></span><span class="anchor" id="line-2181"></span><span class="anchor" id="line-2182"></span><span class="anchor" id="line-2183"></span><span class="anchor" id="line-2184"></span><span class="anchor" id="line-2185"></span><span class="anchor" id="line-2186"></span><span class="anchor" id="line-2187"></span><span class="anchor" id="line-2188"></span><span class="anchor" id="line-2189"></span><span class="anchor" id="line-2190"></span><span class="anchor" id="line-2191"></span><span class="anchor" id="line-2192"></span><span class="anchor" id="line-2193"></span><span class="anchor" id="line-2194"></span><span class="anchor" id="line-2195"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-57610e671e6939943fcb0e97d18f0c9186b75581\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-57610e671e6939943fcb0e97d18f0c9186b75581', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-57610e671e6939943fcb0e97d18f0c9186b75581" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># staticbox.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ResWord">class</span> <span class="ID">MyDialog</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Dialog</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   8 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Dialog</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">250</span><span class="Operator">,</span> <span class="Number">230</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  10 </span></span>
<span class="line"><span class="LineNumber">  11 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticBox</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Personal Info'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">5</span><span class="Operator">,</span> <span class="Number">5</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">240</span><span class="Operator">,</span> <span class="Number">170</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">CheckBox</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span> <span class="Operator">,</span><span class="String">'Male'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">15</span><span class="Operator">,</span> <span class="Number">30</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">CheckBox</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span> <span class="Operator">,</span><span class="String">'Married'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">15</span><span class="Operator">,</span> <span class="Number">55</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Age'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">15</span><span class="Operator">,</span> <span class="Number">95</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">SpinCtrl</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'1'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">55</span><span class="Operator">,</span> <span class="Number">90</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">60</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">min</span><span class="Operator">=</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">max</span><span class="Operator">=</span><span class="Number">120</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="String">'Ok'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">90</span><span class="Operator">,</span> <span class="Number">185</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">60</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span></span>
<span class="line"><span class="LineNumber">  18 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnClose</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  19 </span></span>
<span class="line"><span class="LineNumber">  20 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  21 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">ShowModal</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  22 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Destroy</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  23 </span></span>
<span class="line"><span class="LineNumber">  24 </span>    <span class="ResWord">def</span> <span class="ID">OnClose</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  25 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Close</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  26 </span></span>
<span class="line"><span class="LineNumber">  27 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  28 </span><span class="ID">MyDialog</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'staticbox.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  29 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-2196"></span><p class="line867"><img alt="staticbox.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_012.png" title="staticbox.png"> <span class="anchor" id="line-2197"></span><span class="anchor" id="line-2198"></span></p><p class="line867"><strong>Figure staticbox.py</strong> <span class="anchor" id="line-2199"></span><span class="anchor" id="line-2200"></span></p><p class="line867">
</p><h3 id="wx.ComboBox">wx.ComboBox</h3>
<span class="anchor" id="line-2201"></span><p class="line867"><tt>wx.ComboBox</tt>
 is a combination of a single line text field, a button with a down 
arrow image and a listbox. When you press the button, a listbox appears.
 User can select only one option from the supplied string list. <span class="anchor" id="line-2202"></span><span class="anchor" id="line-2203"></span></p><p class="line867"><tt>wx.ComboBox</tt> has the following constructor: <span class="anchor" id="line-2204"></span><span class="anchor" id="line-2205"></span></p><p class="line867"><span class="anchor" id="line-2206"></span><span class="anchor" id="line-2207"></span><span class="anchor" id="line-2208"></span><span class="anchor" id="line-2209"></span></p><pre>wx.ComboBox(int id, string value='', wx.Point pos=wx.DefaultPosition, wx.Size size=wx.DefaultSize,
            wx.List choices=wx.EmptyList, int style=0, wx.Validator validator=wx.DefaultValidator,
            string name=wx.ComboBoxNameStr)</pre><span class="anchor" id="line-2210"></span><p class="line867"><strong><tt>wx.ComboBox</tt> styles</strong> <span class="anchor" id="line-2211"></span><span class="anchor" id="line-2212"></span></p><ul><li>wx.CB_DROPDOWN <span class="anchor" id="line-2213"></span></li><li>wx.CB_READONLY <span class="anchor" id="line-2214"></span></li><li>wx.CB_SORT <span class="anchor" id="line-2215"></span><span class="anchor" id="line-2216"></span></li></ul><div><table><tbody><tr>  <td colspan="2" style="text-align: center;"><p class="line891"><strong><tt>wx.ComboBox&nbsp;methods</tt></strong> </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-2217"></span><p class="line891"><tt>string&nbsp;GetValue()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">return the current value</p></td>
</tr>
<tr>  <td><span class="anchor" id="line-2218"></span><p class="line891"><tt>SetValue(string&nbsp;value)</tt> </p></td>
  <td><p class="line862">set the value into the textfield of the combobox</p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-2219"></span><p class="line891"><tt>Copy()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">copy the selected value to the clipboard</p></td>
</tr>
<tr>  <td><span class="anchor" id="line-2220"></span><p class="line891"><tt>Cut()</tt> </p></td>
  <td><p class="line862">cut the selected value to the clipboard</p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-2221"></span><p class="line891"><tt>Paste()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">paste text from the clipboard to the combobox's text field</p></td>
</tr>
<tr>  <td><span class="anchor" id="line-2222"></span><p class="line891"><tt>SetInsertionPoint(int&nbsp;pos)</tt> </p></td>
  <td><p class="line862">set the insertion point in the combobox's text field</p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-2223"></span><p class="line891"><tt>int&nbsp;GetInsertionPoint()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">get the insertion point for the combobox's text field</p></td>
</tr>
<tr>  <td><span class="anchor" id="line-2224"></span><p class="line891"><tt>int&nbsp;GetLastPosition()</tt> </p></td>
  <td><p class="line862">return the last position in the combobox's text field</p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-2225"></span><p class="line891"><tt>Replace(int&nbsp;from,&nbsp;int&nbsp;to,&nbsp;string&nbsp;value)</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">replace the text between from and to positions in the combobox's text field</p></td>
</tr>
<tr>  <td><span class="anchor" id="line-2226"></span><p class="line891"><tt>SetSelection(int&nbsp;n)</tt> </p></td>
  <td><p class="line862">select the item at position n</p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-2227"></span><p class="line891"><tt>SetMark(int&nbsp;from,&nbsp;int&nbsp;to)</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">select the text between from and to positions in the combobox's text field</p></td>
</tr>
<tr>  <td><span class="anchor" id="line-2228"></span><p class="line891"><tt>(int&nbsp;from,&nbsp;int&nbsp;to)&nbsp;GetMark()</tt> </p></td>
  <td><p class="line862">return the from and to positions of the selected text in the combobox's text field</p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-2229"></span><p class="line891"><tt>int&nbsp;GetCurrentSelection()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">return the current selection</p></td>
</tr>
<tr>  <td><span class="anchor" id="line-2230"></span><p class="line891"><tt>bool&nbsp;SetStringSelection(string&nbsp;string)</tt> </p></td>
  <td><p class="line862">select the item with the specified string</p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-2231"></span><p class="line891"><tt>int&nbsp;SetString(int&nbsp;n,&nbsp;string&nbsp;string)</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">set the label for the item at position n</p></td>
</tr>
<tr>  <td><span class="anchor" id="line-2232"></span><p class="line891"><tt>bool&nbsp;SetEditable(bool&nbsp;editable)</tt> </p></td>
  <td><p class="line862">toggle readonly flag for the combobox's text field</p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-2233"></span><p class="line891"><tt>int&nbsp;SetInsertionPointEnd()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862"> set the insertion point at the end of the combobox's text field.</p></td>
</tr>
<tr>  <td><span class="anchor" id="line-2234"></span><p class="line891"><tt>Remove(int&nbsp;from,&nbsp;int&nbsp;to)</tt> </p></td>
  <td><p class="line862">remove the text between the two positions in the combobox's text field</p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-2235"></span><p class="line891"><tt>bool&nbsp;IsEditable()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">return true if the combobox is editable </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-2236"></span><p class="line891"><tt>SelectAll(int&nbsp;from,&nbsp;int&nbsp;to)</tt> </p></td>
  <td><p class="line862">select all the text in the combo's text field</p></td>
</tr>
</tbody></table></div><span class="anchor" id="line-2237"></span><span class="anchor" id="line-2238"></span><span class="anchor" id="line-2239"></span><p class="line867"><span class="anchor" id="line-2240"></span><span class="anchor" id="line-2241"></span><span class="anchor" id="line-2242"></span><span class="anchor" id="line-2243"></span><span class="anchor" id="line-2244"></span><span class="anchor" id="line-2245"></span><span class="anchor" id="line-2246"></span><span class="anchor" id="line-2247"></span><span class="anchor" id="line-2248"></span><span class="anchor" id="line-2249"></span><span class="anchor" id="line-2250"></span><span class="anchor" id="line-2251"></span><span class="anchor" id="line-2252"></span><span class="anchor" id="line-2253"></span><span class="anchor" id="line-2254"></span><span class="anchor" id="line-2255"></span><span class="anchor" id="line-2256"></span><span class="anchor" id="line-2257"></span><span class="anchor" id="line-2258"></span><span class="anchor" id="line-2259"></span><span class="anchor" id="line-2260"></span><span class="anchor" id="line-2261"></span><span class="anchor" id="line-2262"></span><span class="anchor" id="line-2263"></span><span class="anchor" id="line-2264"></span><span class="anchor" id="line-2265"></span><span class="anchor" id="line-2266"></span><span class="anchor" id="line-2267"></span><span class="anchor" id="line-2268"></span><span class="anchor" id="line-2269"></span><span class="anchor" id="line-2270"></span><span class="anchor" id="line-2271"></span><span class="anchor" id="line-2272"></span><span class="anchor" id="line-2273"></span><span class="anchor" id="line-2274"></span><span class="anchor" id="line-2275"></span><span class="anchor" id="line-2276"></span><span class="anchor" id="line-2277"></span><span class="anchor" id="line-2278"></span><span class="anchor" id="line-2279"></span><span class="anchor" id="line-2280"></span><span class="anchor" id="line-2281"></span><span class="anchor" id="line-2282"></span><span class="anchor" id="line-2283"></span><span class="anchor" id="line-2284"></span><span class="anchor" id="line-2285"></span><span class="anchor" id="line-2286"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-1d6a08f010ab52197dcc2b1b591aba04c54f4245\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-1d6a08f010ab52197dcc2b1b591aba04c54f4245', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-1d6a08f010ab52197dcc2b1b591aba04c54f4245" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># combobox.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ResWord">class</span> <span class="ID">MyDialog</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Dialog</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   8 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Dialog</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">250</span><span class="Operator">,</span> <span class="Number">270</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  10 </span></span>
<span class="line"><span class="LineNumber">  11 </span>        <span class="ID">panel</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">75</span><span class="Operator">,</span> <span class="Number">20</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">100</span><span class="Operator">,</span> <span class="Number">127</span><span class="Operator">)</span><span class="Operator">,</span>  <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">SUNKEN_BORDER</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">picture</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticBitmap</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">panel</span><span class="Operator">.</span><span class="ID">SetBackgroundColour</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">WHITE</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">images</span> <span class="Operator">=</span> <span class="Operator">[</span><span class="String">'tolstoy.jpg'</span><span class="Operator">,</span> <span class="String">'feuchtwanger.jpg'</span><span class="Operator">,</span> <span class="String">'balzac.jpg'</span><span class="Operator">,</span> <span class="String">'pasternak.jpg'</span><span class="Operator">,</span> <span class="String">'galsworthy.jpg'</span><span class="Operator">,</span> <span class="String">'wolfe.jpg'</span><span class="Operator">,</span> <span class="String">'zweig.jpg'</span><span class="Operator">]</span></span>
<span class="line"><span class="LineNumber">  16 </span>        <span class="ID">authors</span> <span class="Operator">=</span> <span class="Operator">[</span><span class="String">'Leo Tolstoy'</span><span class="Operator">,</span> <span class="String">'Lion Feuchtwanger'</span><span class="Operator">,</span> <span class="String">'Honore de Balzac'</span><span class="Operator">,</span> <span class="String">'Boris Pasternak'</span><span class="Operator">,</span> <span class="String">'John Galsworthy'</span><span class="Operator">,</span> <span class="String">'Tom Wolfe'</span><span class="Operator">,</span> <span class="String">'Stefan Zweig'</span> <span class="Operator">]</span></span>
<span class="line"><span class="LineNumber">  17 </span></span>
<span class="line"><span class="LineNumber">  18 </span></span>
<span class="line"><span class="LineNumber">  19 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ComboBox</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">pos</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">50</span><span class="Operator">,</span> <span class="Number">170</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">150</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">choices</span><span class="Operator">=</span><span class="ID">authors</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">CB_READONLY</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  20 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="String">'Close'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">80</span><span class="Operator">,</span> <span class="Number">220</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  21 </span></span>
<span class="line"><span class="LineNumber">  22 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnClose</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  23 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_COMBOBOX</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnSelect</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  24 </span></span>
<span class="line"><span class="LineNumber">  25 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  26 </span></span>
<span class="line"><span class="LineNumber">  27 </span>    <span class="ResWord">def</span> <span class="ID">OnClose</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  28 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Close</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  29 </span></span>
<span class="line"><span class="LineNumber">  30 </span>    <span class="ResWord">def</span> <span class="ID">OnSelect</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  31 </span>        <span class="ID">item</span> <span class="Operator">=</span> <span class="ID">event</span><span class="Operator">.</span><span class="ID">GetSelection</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  32 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">picture</span><span class="Operator">.</span><span class="ID">SetFocus</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  33 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">picture</span><span class="Operator">.</span><span class="ID">SetBitmap</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bitmap</span><span class="Operator">(</span><span class="String">'images/'</span> <span class="Operator">+</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">images</span><span class="Operator">[</span><span class="ID">item</span><span class="Operator">]</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  34 </span></span>
<span class="line"><span class="LineNumber">  35 </span></span>
<span class="line"><span class="LineNumber">  36 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  37 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  38 </span>        <span class="ID">dlg</span> <span class="Operator">=</span> <span class="ID">MyDialog</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'combobox.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  39 </span>        <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">ShowModal</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  40 </span>        <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">Destroy</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  41 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  42 </span></span>
<span class="line"><span class="LineNumber">  43 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  44 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-2287"></span><p class="line867"><img alt="combobox.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_009.png" title="combobox.png"> <span class="anchor" id="line-2288"></span><span class="anchor" id="line-2289"></span></p><p class="line867"><strong>Figure: combobox.py</strong> <span class="anchor" id="line-2290"></span><span class="anchor" id="line-2291"></span></p><p class="line867">
</p><h3 id="wx.CheckBox">wx.CheckBox</h3>
<span class="anchor" id="line-2292"></span><p class="line867"><tt>wx.CheckBox</tt>
 is a widget that has two states. On and Off. It is a box with a label. 
The label can be set to the right or to the left of the box. If the 
checkbox is checked, it is represented by a tick in a  box. <span class="anchor" id="line-2293"></span><span class="anchor" id="line-2294"></span></p><p class="line867"><strong><tt>wx.CheckBox&nbsp;Styles</tt></strong> <span class="anchor" id="line-2295"></span><span class="anchor" id="line-2296"></span></p><ul><li>wx.ALIGN_RIGHT <span class="anchor" id="line-2297"></span><span class="anchor" id="line-2298"></span></li></ul><div><table><tbody><tr>  <td colspan="2" style="text-align: center;"><p class="line891"><strong><tt>wx.CheckBox&nbsp;methods</tt></strong> </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-2299"></span><p class="line891"><tt>bool&nbsp;GetValue()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">get the state of the checkbox </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-2300"></span><p class="line891"><tt>bool&nbsp;IsChecked()</tt> </p></td>
  <td><p class="line862">determine the checkbox state </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-2301"></span><p class="line891"><tt>SetValue(bool&nbsp;state)</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">set the state of the checkbox </p></td>
</tr>
</tbody></table></div><span class="anchor" id="line-2302"></span><span class="anchor" id="line-2303"></span><span class="anchor" id="line-2304"></span><p class="line867"><span class="anchor" id="line-2305"></span><span class="anchor" id="line-2306"></span><span class="anchor" id="line-2307"></span><span class="anchor" id="line-2308"></span><span class="anchor" id="line-2309"></span><span class="anchor" id="line-2310"></span><span class="anchor" id="line-2311"></span><span class="anchor" id="line-2312"></span><span class="anchor" id="line-2313"></span><span class="anchor" id="line-2314"></span><span class="anchor" id="line-2315"></span><span class="anchor" id="line-2316"></span><span class="anchor" id="line-2317"></span><span class="anchor" id="line-2318"></span><span class="anchor" id="line-2319"></span><span class="anchor" id="line-2320"></span><span class="anchor" id="line-2321"></span><span class="anchor" id="line-2322"></span><span class="anchor" id="line-2323"></span><span class="anchor" id="line-2324"></span><span class="anchor" id="line-2325"></span><span class="anchor" id="line-2326"></span><span class="anchor" id="line-2327"></span><span class="anchor" id="line-2328"></span><span class="anchor" id="line-2329"></span><span class="anchor" id="line-2330"></span><span class="anchor" id="line-2331"></span><span class="anchor" id="line-2332"></span><span class="anchor" id="line-2333"></span><span class="anchor" id="line-2334"></span><span class="anchor" id="line-2335"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-5d4658c2a801ed77fe8b95507d8ba955a7ffe7a6\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-5d4658c2a801ed77fe8b95507d8ba955a7ffe7a6', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-5d4658c2a801ed77fe8b95507d8ba955a7ffe7a6" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># checkbox.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ResWord">class</span> <span class="ID">MyCheckBox</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   8 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">250</span><span class="Operator">,</span> <span class="Number">170</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  10 </span></span>
<span class="line"><span class="LineNumber">  11 </span>        <span class="ID">panel</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">cb</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">CheckBox</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Show Title'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">10</span><span class="Operator">,</span> <span class="Number">10</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">cb</span><span class="Operator">.</span><span class="ID">SetValue</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_CHECKBOX</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">cb</span><span class="Operator">.</span><span class="ID">GetId</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">ShowTitle</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  18 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  19 </span></span>
<span class="line"><span class="LineNumber">  20 </span>    <span class="ResWord">def</span> <span class="ID">ShowTitle</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  21 </span>        <span class="ResWord">if</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">cb</span><span class="Operator">.</span><span class="ID">GetValue</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  22 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetTitle</span><span class="Operator">(</span><span class="String">'checkbox.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  23 </span>        <span class="ResWord">else</span><span class="Operator">:</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetTitle</span><span class="Operator">(</span><span class="String">''</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  24 </span></span>
<span class="line"><span class="LineNumber">  25 </span></span>
<span class="line"><span class="LineNumber">  26 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  27 </span><span class="ID">MyCheckBox</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'checkbox.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  28 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-2336"></span><p class="line874">In our script we toggle the visibility of the title. <span class="anchor" id="line-2337"></span><span class="anchor" id="line-2338"></span></p><p class="line867"><img alt="checkbox.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_052.png" title="checkbox.png"> <span class="anchor" id="line-2339"></span><span class="anchor" id="line-2340"></span></p><p class="line867"><strong>Figure: checkbox.py</strong> <span class="anchor" id="line-2341"></span><span class="anchor" id="line-2342"></span></p><p class="line867">
</p><h3 id="wx.StatusBar">wx.StatusBar</h3>
<span class="anchor" id="line-2343"></span><p class="line862">As it's name indicates, the<tt>wx.StatusBar</tt>
 widget is used to display application status information. It can be 
divided into several parts to show different kind of information. We can
 insert other widgets into the <tt>wx.StatusBar</tt>. It can be used as an alternative to dialogs, since dialogs are ofted abused and are disliked by most users. We can create a <span class="anchor" id="line-2344"></span><span class="anchor" id="line-2345"></span></p><p class="line867"><tt>wx.StatusBar</tt> in two ways. We can manually create our own <tt>wx.StatusBar</tt> and call <tt>SetStatusBar()</tt> method or we can simply call a <tt>CreateStatusBar()</tt> method. The latter method creates a default <tt>wx.StatusBar</tt> for us.  In our first example, we have a <span class="anchor" id="line-2346"></span><span class="anchor" id="line-2347"></span></p><p class="line867"><tt>wx.Frame</tt> widget and five other widgets. If we hover a mouse pointer over a widget, it's description is shown on the <tt>wx.StatusBar</tt> <span class="anchor" id="line-2348"></span><span class="anchor" id="line-2349"></span></p><p class="line867"><span class="anchor" id="line-2350"></span><span class="anchor" id="line-2351"></span><span class="anchor" id="line-2352"></span><span class="anchor" id="line-2353"></span><span class="anchor" id="line-2354"></span><span class="anchor" id="line-2355"></span><span class="anchor" id="line-2356"></span><span class="anchor" id="line-2357"></span><span class="anchor" id="line-2358"></span><span class="anchor" id="line-2359"></span><span class="anchor" id="line-2360"></span><span class="anchor" id="line-2361"></span><span class="anchor" id="line-2362"></span><span class="anchor" id="line-2363"></span><span class="anchor" id="line-2364"></span><span class="anchor" id="line-2365"></span><span class="anchor" id="line-2366"></span><span class="anchor" id="line-2367"></span><span class="anchor" id="line-2368"></span><span class="anchor" id="line-2369"></span><span class="anchor" id="line-2370"></span><span class="anchor" id="line-2371"></span><span class="anchor" id="line-2372"></span><span class="anchor" id="line-2373"></span><span class="anchor" id="line-2374"></span><span class="anchor" id="line-2375"></span><span class="anchor" id="line-2376"></span><span class="anchor" id="line-2377"></span><span class="anchor" id="line-2378"></span><span class="anchor" id="line-2379"></span><span class="anchor" id="line-2380"></span><span class="anchor" id="line-2381"></span><span class="anchor" id="line-2382"></span><span class="anchor" id="line-2383"></span><span class="anchor" id="line-2384"></span><span class="anchor" id="line-2385"></span><span class="anchor" id="line-2386"></span><span class="anchor" id="line-2387"></span><span class="anchor" id="line-2388"></span><span class="anchor" id="line-2389"></span><span class="anchor" id="line-2390"></span><span class="anchor" id="line-2391"></span><span class="anchor" id="line-2392"></span><span class="anchor" id="line-2393"></span><span class="anchor" id="line-2394"></span><span class="anchor" id="line-2395"></span><span class="anchor" id="line-2396"></span><span class="anchor" id="line-2397"></span><span class="anchor" id="line-2398"></span><span class="anchor" id="line-2399"></span><span class="anchor" id="line-2400"></span><span class="anchor" id="line-2401"></span><span class="anchor" id="line-2402"></span><span class="anchor" id="line-2403"></span><span class="anchor" id="line-2404"></span><span class="anchor" id="line-2405"></span><span class="anchor" id="line-2406"></span><span class="anchor" id="line-2407"></span><span class="anchor" id="line-2408"></span><span class="anchor" id="line-2409"></span><span class="anchor" id="line-2410"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-770f2f367e4289f3b3f02d66e4e5102aeebf3883\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-770f2f367e4289f3b3f02d66e4e5102aeebf3883', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-770f2f367e4289f3b3f02d66e4e5102aeebf3883" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># statusbar.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ResWord">class</span> <span class="ID">MyStatusBar</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   8 </span>        <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>                <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">250</span><span class="Operator">,</span> <span class="Number">200</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">CAPTION</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">SYSTEM_MENU</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">CLOSE_BOX</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  10 </span></span>
<span class="line"><span class="LineNumber">  11 </span>                <span class="ID">panel</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  12 </span></span>
<span class="line"><span class="LineNumber">  13 </span>                <span class="ID">button</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="Number">2</span><span class="Operator">,</span> <span class="String">'Button'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">20</span><span class="Operator">,</span> <span class="Number">20</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>                <span class="ID">text</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">CheckBox</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="Number">3</span><span class="Operator">,</span> <span class="String">'CheckBox'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">20</span><span class="Operator">,</span> <span class="Number">90</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span>                <span class="ID">combo</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ComboBox</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="Number">4</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">120</span><span class="Operator">,</span> <span class="Number">22</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span>                <span class="ID">slider</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Slider</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="Number">5</span><span class="Operator">,</span> <span class="Number">6</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="Number">10</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">120</span><span class="Operator">,</span> <span class="Number">90</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">110</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span></span>
<span class="line"><span class="LineNumber">  18 </span></span>
<span class="line"><span class="LineNumber">  19 </span>                <span class="ID">panel</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_ENTER_WINDOW</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">EnterPanel</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  20 </span>                <span class="ID">button</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_ENTER_WINDOW</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">EnterButton</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">2</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  21 </span>                <span class="ID">text</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_ENTER_WINDOW</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">EnterText</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">3</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  22 </span>                <span class="ID">combo</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_ENTER_WINDOW</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">EnterCombo</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">4</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  23 </span>                <span class="ID">slider</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_ENTER_WINDOW</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">EnterSlider</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">5</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  24 </span></span>
<span class="line"><span class="LineNumber">  25 </span></span>
<span class="line"><span class="LineNumber">  26 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">sb</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">CreateStatusBar</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  27 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetMaxSize</span><span class="Operator">(</span><span class="Operator">(</span><span class="Number">250</span><span class="Operator">,</span> <span class="Number">200</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  28 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetMinSize</span><span class="Operator">(</span><span class="Operator">(</span><span class="Number">250</span><span class="Operator">,</span> <span class="Number">200</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  29 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  30 </span></span>
<span class="line"><span class="LineNumber">  31 </span></span>
<span class="line"><span class="LineNumber">  32 </span>        <span class="ResWord">def</span> <span class="ID">EnterButton</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  33 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">sb</span><span class="Operator">.</span><span class="ID">SetStatusText</span><span class="Operator">(</span><span class="String">'Button widget'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  34 </span>                <span class="ID">event</span><span class="Operator">.</span><span class="ID">Skip</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  35 </span></span>
<span class="line"><span class="LineNumber">  36 </span>        <span class="ResWord">def</span> <span class="ID">EnterPanel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  37 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">sb</span><span class="Operator">.</span><span class="ID">SetStatusText</span><span class="Operator">(</span><span class="String">'Panel widget'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  38 </span>                <span class="ID">event</span><span class="Operator">.</span><span class="ID">Skip</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  39 </span></span>
<span class="line"><span class="LineNumber">  40 </span>        <span class="ResWord">def</span> <span class="ID">EnterText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  41 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">sb</span><span class="Operator">.</span><span class="ID">SetStatusText</span><span class="Operator">(</span><span class="String">'CheckBox widget'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  42 </span>                <span class="ID">event</span><span class="Operator">.</span><span class="ID">Skip</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  43 </span></span>
<span class="line"><span class="LineNumber">  44 </span>        <span class="ResWord">def</span> <span class="ID">EnterCombo</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  45 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">sb</span><span class="Operator">.</span><span class="ID">SetStatusText</span><span class="Operator">(</span><span class="String">'ComboBox widget'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  46 </span>                <span class="ID">event</span><span class="Operator">.</span><span class="ID">Skip</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  47 </span></span>
<span class="line"><span class="LineNumber">  48 </span>        <span class="ResWord">def</span> <span class="ID">EnterSlider</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  49 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">sb</span><span class="Operator">.</span><span class="ID">SetStatusText</span><span class="Operator">(</span><span class="String">'Slider widget'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  50 </span>                <span class="ID">event</span><span class="Operator">.</span><span class="ID">Skip</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  51 </span></span>
<span class="line"><span class="LineNumber">  52 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  53 </span>        <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  54 </span>                <span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">MyStatusBar</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'statusbar.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  55 </span>                <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  56 </span>                <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  57 </span></span>
<span class="line"><span class="LineNumber">  58 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  59 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-2411"></span><p class="line867"><img alt="statusbar.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_045.png" title="statusbar.png"> <span class="anchor" id="line-2412"></span><span class="anchor" id="line-2413"></span></p><p class="line867"><strong>Figure: statusbar.py</strong> <span class="anchor" id="line-2414"></span><span class="anchor" id="line-2415"></span></p><p class="line867">
</p><h3 id="wx.RadioButton">wx.RadioButton</h3>
<span class="anchor" id="line-2416"></span><p class="line867"><tt>wx.RadioButton&nbsp;</tt>
 is a widget that allows the user to select a single exclusive choice 
from a group of options. A group of radio buttons is defined by having 
the first <tt>RadioButton</tt> in the group contain the wx.RB_GROUP style. All other <tt>RadioButtons</tt> defined after the first <tt>RadioButton</tt> with this style flag is set will be added to the function group of the first <tt>RadioButton</tt>. Declaring another <tt>RadioButton</tt> with the wx.RB_GROUP flag will start a new radio button group. <span class="anchor" id="line-2417"></span><span class="anchor" id="line-2418"></span></p><p class="line867"><strong><tt>wx.RadioButton&nbsp;Styles</tt></strong> <span class="anchor" id="line-2419"></span><span class="anchor" id="line-2420"></span></p><ul><li>wx.RB_GROUP <span class="anchor" id="line-2421"></span></li><li>wx.RB_SINGLE <span class="anchor" id="line-2422"></span><span class="anchor" id="line-2423"></span></li></ul><div><table><tbody><tr>  <td colspan="2" style="text-align: center;"><p class="line891"><strong><tt>wx.RadioButton&nbsp;methods</tt></strong> </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-2424"></span><p class="line891"><tt>bool&nbsp;GetValue()</tt> </p></td>
  <td><p class="line862">returns True or False depending on the selection state </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-2425"></span><p class="line891"><tt>SetValue(bool&nbsp;state)</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line891"><tt>RadioButton</tt> </p></td>
</tr>
</tbody></table></div><span class="anchor" id="line-2426"></span><span class="anchor" id="line-2427"></span><span class="anchor" id="line-2428"></span><p class="line867"><span class="anchor" id="line-2429"></span><span class="anchor" id="line-2430"></span><span class="anchor" id="line-2431"></span><span class="anchor" id="line-2432"></span><span class="anchor" id="line-2433"></span><span class="anchor" id="line-2434"></span><span class="anchor" id="line-2435"></span><span class="anchor" id="line-2436"></span><span class="anchor" id="line-2437"></span><span class="anchor" id="line-2438"></span><span class="anchor" id="line-2439"></span><span class="anchor" id="line-2440"></span><span class="anchor" id="line-2441"></span><span class="anchor" id="line-2442"></span><span class="anchor" id="line-2443"></span><span class="anchor" id="line-2444"></span><span class="anchor" id="line-2445"></span><span class="anchor" id="line-2446"></span><span class="anchor" id="line-2447"></span><span class="anchor" id="line-2448"></span><span class="anchor" id="line-2449"></span><span class="anchor" id="line-2450"></span><span class="anchor" id="line-2451"></span><span class="anchor" id="line-2452"></span><span class="anchor" id="line-2453"></span><span class="anchor" id="line-2454"></span><span class="anchor" id="line-2455"></span><span class="anchor" id="line-2456"></span><span class="anchor" id="line-2457"></span><span class="anchor" id="line-2458"></span><span class="anchor" id="line-2459"></span><span class="anchor" id="line-2460"></span><span class="anchor" id="line-2461"></span><span class="anchor" id="line-2462"></span><span class="anchor" id="line-2463"></span><span class="anchor" id="line-2464"></span><span class="anchor" id="line-2465"></span><span class="anchor" id="line-2466"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-6055ee38a0b6c664e2a1c4b57501a5488d532d45\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-6055ee38a0b6c664e2a1c4b57501a5488d532d45', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-6055ee38a0b6c664e2a1c4b57501a5488d532d45" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># radiobuttons.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ResWord">class</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   8 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">DefaultPosition</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Size</span><span class="Operator">(</span><span class="Number">200</span><span class="Operator">,</span> <span class="Number">150</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  10 </span>        <span class="ID">panel</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  11 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">rb1</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">RadioButton</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Value A'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">10</span><span class="Operator">,</span> <span class="Number">10</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">RB_GROUP</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">rb2</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">RadioButton</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Value B'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">10</span><span class="Operator">,</span> <span class="Number">30</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">rb3</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">RadioButton</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Value C'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">10</span><span class="Operator">,</span> <span class="Number">50</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_RADIOBUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetVal</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">rb1</span><span class="Operator">.</span><span class="ID">GetId</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_RADIOBUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetVal</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">rb2</span><span class="Operator">.</span><span class="ID">GetId</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_RADIOBUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetVal</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">rb3</span><span class="Operator">.</span><span class="ID">GetId</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">statusbar</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">CreateStatusBar</span><span class="Operator">(</span><span class="Number">3</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  18 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetVal</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  19 </span></span>
<span class="line"><span class="LineNumber">  20 </span>    <span class="ResWord">def</span> <span class="ID">SetVal</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  21 </span>        <span class="ID">state1</span> <span class="Operator">=</span> <span class="ID">str</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">rb1</span><span class="Operator">.</span><span class="ID">GetValue</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  22 </span>        <span class="ID">state2</span> <span class="Operator">=</span> <span class="ID">str</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">rb2</span><span class="Operator">.</span><span class="ID">GetValue</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  23 </span>        <span class="ID">state3</span> <span class="Operator">=</span> <span class="ID">str</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">rb3</span><span class="Operator">.</span><span class="ID">GetValue</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  24 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">statusbar</span><span class="Operator">.</span><span class="ID">SetStatusText</span><span class="Operator">(</span><span class="ID">state1</span><span class="Operator">,</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  25 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">statusbar</span><span class="Operator">.</span><span class="ID">SetStatusText</span><span class="Operator">(</span><span class="ID">state2</span><span class="Operator">,</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  26 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">statusbar</span><span class="Operator">.</span><span class="ID">SetStatusText</span><span class="Operator">(</span><span class="ID">state3</span><span class="Operator">,</span><span class="Number">2</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  27 </span></span>
<span class="line"><span class="LineNumber">  28 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  29 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  30 </span>        <span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'radiobuttons.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  31 </span>        <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  32 </span>        <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Center</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  33 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  34 </span></span>
<span class="line"><span class="LineNumber">  35 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  36 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-2467"></span><p class="line867"><img alt="radiobuttons.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_044.png" title="radiobuttons.png"> <span class="anchor" id="line-2468"></span><span class="anchor" id="line-2469"></span></p><p class="line867"><strong>Figure: radiobuttons.py</strong> <span class="anchor" id="line-2470"></span><span class="anchor" id="line-2471"></span></p><p class="line867">
</p><h3 id="wx.Gauge">wx.Gauge</h3>
<span class="anchor" id="line-2472"></span><p class="line867"><tt>wx.Gauge</tt> is a widget that is used, when we process lengthy tasks. <span class="anchor" id="line-2473"></span><span class="anchor" id="line-2474"></span></p><p class="line867"><strong><tt>wx.Gauge&nbsp;styles</tt></strong> <span class="anchor" id="line-2475"></span><span class="anchor" id="line-2476"></span></p><ul><li>wx.GA_HORIZONTAL <span class="anchor" id="line-2477"></span></li><li>wx.GA_VERTICAL <span class="anchor" id="line-2478"></span><span class="anchor" id="line-2479"></span></li></ul><div><table><tbody><tr>  <td colspan="2" style="text-align: center;"><p class="line891"><strong><tt>wx.Gauge&nbsp;methods</tt></strong> </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-2480"></span><p class="line891"><tt>SetRange(integer&nbsp;range)</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">set the maximum value of the gauge </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-2481"></span><p class="line891"><tt>integer&nbsp;GetRange()</tt> </p></td>
  <td><p class="line862">get the maximum value of the gauge </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-2482"></span><p class="line891"><tt>SetValue(integer&nbsp;position)</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">set the position of the gauge </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-2483"></span><p class="line891"><tt>integer&nbsp;GetValue()</tt> </p></td>
  <td><p class="line862">get the position of the gauge </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-2484"></span><p class="line891"><tt>bool&nbsp;IsVertical()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">check if the gauge is vertical </p></td>
</tr>
</tbody></table></div><span class="anchor" id="line-2485"></span><span class="anchor" id="line-2486"></span><span class="anchor" id="line-2487"></span><p class="line867"><span class="anchor" id="line-2488"></span><span class="anchor" id="line-2489"></span><span class="anchor" id="line-2490"></span><span class="anchor" id="line-2491"></span><span class="anchor" id="line-2492"></span><span class="anchor" id="line-2493"></span><span class="anchor" id="line-2494"></span><span class="anchor" id="line-2495"></span><span class="anchor" id="line-2496"></span><span class="anchor" id="line-2497"></span><span class="anchor" id="line-2498"></span><span class="anchor" id="line-2499"></span><span class="anchor" id="line-2500"></span><span class="anchor" id="line-2501"></span><span class="anchor" id="line-2502"></span><span class="anchor" id="line-2503"></span><span class="anchor" id="line-2504"></span><span class="anchor" id="line-2505"></span><span class="anchor" id="line-2506"></span><span class="anchor" id="line-2507"></span><span class="anchor" id="line-2508"></span><span class="anchor" id="line-2509"></span><span class="anchor" id="line-2510"></span><span class="anchor" id="line-2511"></span><span class="anchor" id="line-2512"></span><span class="anchor" id="line-2513"></span><span class="anchor" id="line-2514"></span><span class="anchor" id="line-2515"></span><span class="anchor" id="line-2516"></span><span class="anchor" id="line-2517"></span><span class="anchor" id="line-2518"></span><span class="anchor" id="line-2519"></span><span class="anchor" id="line-2520"></span><span class="anchor" id="line-2521"></span><span class="anchor" id="line-2522"></span><span class="anchor" id="line-2523"></span><span class="anchor" id="line-2524"></span><span class="anchor" id="line-2525"></span><span class="anchor" id="line-2526"></span><span class="anchor" id="line-2527"></span><span class="anchor" id="line-2528"></span><span class="anchor" id="line-2529"></span><span class="anchor" id="line-2530"></span><span class="anchor" id="line-2531"></span><span class="anchor" id="line-2532"></span><span class="anchor" id="line-2533"></span><span class="anchor" id="line-2534"></span><span class="anchor" id="line-2535"></span><span class="anchor" id="line-2536"></span><span class="anchor" id="line-2537"></span><span class="anchor" id="line-2538"></span><span class="anchor" id="line-2539"></span><span class="anchor" id="line-2540"></span><span class="anchor" id="line-2541"></span><span class="anchor" id="line-2542"></span><span class="anchor" id="line-2543"></span><span class="anchor" id="line-2544"></span><span class="anchor" id="line-2545"></span><span class="anchor" id="line-2546"></span><span class="anchor" id="line-2547"></span><span class="anchor" id="line-2548"></span><span class="anchor" id="line-2549"></span><span class="anchor" id="line-2550"></span><span class="anchor" id="line-2551"></span><span class="anchor" id="line-2552"></span><span class="anchor" id="line-2553"></span><span class="anchor" id="line-2554"></span><span class="anchor" id="line-2555"></span><span class="anchor" id="line-2556"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-eb3a543cafb2a942b1f218e4f99455e8d311f036\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-eb3a543cafb2a942b1f218e4f99455e8d311f036', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-eb3a543cafb2a942b1f218e4f99455e8d311f036" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># gauge.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ResWord">class</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   8 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  10 </span></span>
<span class="line"><span class="LineNumber">  11 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">timer</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Timer</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">count</span> <span class="Operator">=</span> <span class="Number">0</span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_TIMER</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnTimer</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">timer</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">panel</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">vbox</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BoxSizer</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">VERTICAL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span>        <span class="ID">hbox1</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BoxSizer</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">HORIZONTAL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="ID">hbox2</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BoxSizer</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">HORIZONTAL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  18 </span>        <span class="ID">hbox3</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BoxSizer</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">HORIZONTAL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  19 </span></span>
<span class="line"><span class="LineNumber">  20 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">gauge</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Gauge</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="Number">50</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">250</span><span class="Operator">,</span> <span class="Number">25</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  21 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">btn1</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ID_OK</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  22 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">btn2</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ID_STOP</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  23 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">text</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Task to be done'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  24 </span></span>
<span class="line"><span class="LineNumber">  25 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnOk</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">btn1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  26 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnStop</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">btn2</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  27 </span></span>
<span class="line"><span class="LineNumber">  28 </span>        <span class="ID">hbox1</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">gauge</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_CENTRE</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  29 </span>        <span class="ID">hbox2</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">btn1</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">RIGHT</span><span class="Operator">,</span> <span class="Number">10</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  30 </span>        <span class="ID">hbox2</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">btn2</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  31 </span>        <span class="ID">hbox3</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">text</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  32 </span>        <span class="ID">vbox</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">,</span> <span class="Number">50</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  33 </span>        <span class="ID">vbox</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">hbox1</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_CENTRE</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  34 </span>        <span class="ID">vbox</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">,</span> <span class="Number">30</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  35 </span>        <span class="ID">vbox</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">hbox2</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_CENTRE</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  36 </span>        <span class="ID">vbox</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">hbox3</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_CENTRE</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  37 </span>        <span class="ID">panel</span><span class="Operator">.</span><span class="ID">SetSizer</span><span class="Operator">(</span><span class="ID">vbox</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  38 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  39 </span></span>
<span class="line"><span class="LineNumber">  40 </span>    <span class="ResWord">def</span> <span class="ID">OnOk</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  41 </span>        <span class="ResWord">if</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">count</span> <span class="Operator">&gt;=</span> <span class="Number">50</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  42 </span>            <span class="ResWord">return</span></span>
<span class="line"><span class="LineNumber">  43 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">timer</span><span class="Operator">.</span><span class="ID">Start</span><span class="Operator">(</span><span class="Number">100</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  44 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">text</span><span class="Operator">.</span><span class="ID">SetLabel</span><span class="Operator">(</span><span class="String">'Task in Progress'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  45 </span></span>
<span class="line"><span class="LineNumber">  46 </span>    <span class="ResWord">def</span> <span class="ID">OnStop</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  47 </span>        <span class="ResWord">if</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">count</span> <span class="Operator">==</span> <span class="Number">0</span> <span class="ResWord">or</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">count</span> <span class="Operator">&gt;=</span> <span class="Number">50</span> <span class="ResWord">or</span> <span class="ResWord">not</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">timer</span><span class="Operator">.</span><span class="ID">IsRunning</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  48 </span>            <span class="ResWord">return</span></span>
<span class="line"><span class="LineNumber">  49 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">timer</span><span class="Operator">.</span><span class="ID">Stop</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  50 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">text</span><span class="Operator">.</span><span class="ID">SetLabel</span><span class="Operator">(</span><span class="String">'Task Interrupted'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  51 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bell</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  52 </span></span>
<span class="line"><span class="LineNumber">  53 </span>    <span class="ResWord">def</span> <span class="ID">OnTimer</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  54 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">count</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">count</span> <span class="Operator">+</span><span class="Number">1</span></span>
<span class="line"><span class="LineNumber">  55 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">gauge</span><span class="Operator">.</span><span class="ID">SetValue</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">count</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  56 </span>        <span class="ResWord">if</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">count</span> <span class="Operator">==</span> <span class="Number">50</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  57 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">timer</span><span class="Operator">.</span><span class="ID">Stop</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  58 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">text</span><span class="Operator">.</span><span class="ID">SetLabel</span><span class="Operator">(</span><span class="String">'Task Completed'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  59 </span></span>
<span class="line"><span class="LineNumber">  60 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  61 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  62 </span>        <span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'gauge.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  63 </span>        <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  64 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  65 </span></span>
<span class="line"><span class="LineNumber">  66 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  67 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-2557"></span><p class="line867"><img alt="gauge.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_023.png" title="gauge.png"> <span class="anchor" id="line-2558"></span><span class="anchor" id="line-2559"></span></p><p class="line867"><strong>Figure: gauge.py</strong> <span class="anchor" id="line-2560"></span><span class="anchor" id="line-2561"></span></p><p class="line867">
</p><h3 id="wx.Slider">wx.Slider</h3>
<span class="anchor" id="line-2562"></span><p class="line867"><tt>wx.Slider</tt>
 is a widget that has a simple handle. This handle can be pulled back 
and forth. This way we are choosing a value for a specific task. Say we 
want to input into our application the age of a customer. For this 
purpose, <tt>wx.Slider</tt> might be a good choice. <span class="anchor" id="line-2563"></span><span class="anchor" id="line-2564"></span></p><p class="line867"><strong><tt>wx.Slider&nbsp;styles</tt></strong> <span class="anchor" id="line-2565"></span><span class="anchor" id="line-2566"></span></p><ul><li>wxSL_HORIZONTAL <span class="anchor" id="line-2567"></span></li><li>wxSL_VERTICAL <span class="anchor" id="line-2568"></span></li><li>wxSL_AUTOTICKS <span class="anchor" id="line-2569"></span></li><li>wxSL_LABELS <span class="anchor" id="line-2570"></span></li><li>wxSL_LEFT <span class="anchor" id="line-2571"></span></li><li>wxSL_RIGHT <span class="anchor" id="line-2572"></span></li><li>wxSL_TOP <span class="anchor" id="line-2573"></span></li><li>wxSL_BOTTOM <span class="anchor" id="line-2574"></span></li><li>wxSL_INVERSE <span class="anchor" id="line-2575"></span><span class="anchor" id="line-2576"></span></li></ul><div><table><tbody><tr>  <td colspan="2" style="text-align: center;"><p class="line891"><strong><tt>wx.Slider&nbsp;methods</tt></strong> </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-2577"></span><p class="line891"><tt>integer&nbsp;GetValue()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">get the current slider value </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-2578"></span><p class="line891"><tt>SetValue(integer&nbsp;value)</tt> </p></td>
  <td><p class="line862">set the slider position </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-2579"></span><p class="line891"><tt>SetRange(integer&nbsp;min,&nbsp;integer&nbsp;max)</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">set the minimum and maximum slider value </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-2580"></span><p class="line891"><tt>integer&nbsp;GetMin()</tt> </p></td>
  <td><p class="line862">get the minimum slider value </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-2581"></span><p class="line891"><tt>integer&nbsp;GetMax()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">get the maximum slider value </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-2582"></span><p class="line891"><tt>SetMin(integer&nbsp;min)</tt> </p></td>
  <td><p class="line862">set the minimum slider value </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-2583"></span><p class="line891"><tt>integer&nbsp;SetMax(integer&nbsp;max)</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">set the maximum slider value </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-2584"></span><p class="line891"><tt>SetLineSize(integer&nbsp;size)</tt> </p></td>
  <td><p class="line862">set the line size for the slider </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-2585"></span><p class="line891"><tt>SetPageSize(integer&nbsp;pageSize)</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">set the page size for the slider </p></td>
</tr>
</tbody></table></div><span class="anchor" id="line-2586"></span><span class="anchor" id="line-2587"></span><span class="anchor" id="line-2588"></span><p class="line867"><br>
 <span class="anchor" id="line-2589"></span><span class="anchor" id="line-2590"></span></p><p class="line874">pageSize - the number of steps the slider moves when the user pages up or down. <span class="anchor" id="line-2591"></span><span class="anchor" id="line-2592"></span></p><p class="line867"><span class="anchor" id="line-2593"></span><span class="anchor" id="line-2594"></span><span class="anchor" id="line-2595"></span><span class="anchor" id="line-2596"></span><span class="anchor" id="line-2597"></span><span class="anchor" id="line-2598"></span><span class="anchor" id="line-2599"></span><span class="anchor" id="line-2600"></span><span class="anchor" id="line-2601"></span><span class="anchor" id="line-2602"></span><span class="anchor" id="line-2603"></span><span class="anchor" id="line-2604"></span><span class="anchor" id="line-2605"></span><span class="anchor" id="line-2606"></span><span class="anchor" id="line-2607"></span><span class="anchor" id="line-2608"></span><span class="anchor" id="line-2609"></span><span class="anchor" id="line-2610"></span><span class="anchor" id="line-2611"></span><span class="anchor" id="line-2612"></span><span class="anchor" id="line-2613"></span><span class="anchor" id="line-2614"></span><span class="anchor" id="line-2615"></span><span class="anchor" id="line-2616"></span><span class="anchor" id="line-2617"></span><span class="anchor" id="line-2618"></span><span class="anchor" id="line-2619"></span><span class="anchor" id="line-2620"></span><span class="anchor" id="line-2621"></span><span class="anchor" id="line-2622"></span><span class="anchor" id="line-2623"></span><span class="anchor" id="line-2624"></span><span class="anchor" id="line-2625"></span><span class="anchor" id="line-2626"></span><span class="anchor" id="line-2627"></span><span class="anchor" id="line-2628"></span><span class="anchor" id="line-2629"></span><span class="anchor" id="line-2630"></span><span class="anchor" id="line-2631"></span><span class="anchor" id="line-2632"></span><span class="anchor" id="line-2633"></span><span class="anchor" id="line-2634"></span><span class="anchor" id="line-2635"></span><span class="anchor" id="line-2636"></span><span class="anchor" id="line-2637"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-b40faa15d33019491381b4024eae9b68a2490bb5\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-b40faa15d33019491381b4024eae9b68a2490bb5', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-b40faa15d33019491381b4024eae9b68a2490bb5" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># slider.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ResWord">class</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   8 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span></span>
<span class="line"><span class="LineNumber">  10 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">DefaultPosition</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">300</span><span class="Operator">,</span> <span class="Number">150</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  11 </span>        <span class="ID">panel</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  12 </span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">vbox</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BoxSizer</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">VERTICAL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">hbox</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BoxSizer</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">HORIZONTAL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">sld</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Slider</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="Number">200</span><span class="Operator">,</span> <span class="Number">150</span><span class="Operator">,</span> <span class="Number">500</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">DefaultPosition</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">250</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  16 </span>                              <span class="ID">wx</span><span class="Operator">.</span><span class="ID">SL_AUTOTICKS</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">SL_HORIZONTAL</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">SL_LABELS</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="ID">btn1</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="Number">8</span><span class="Operator">,</span> <span class="String">'Adjust'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  18 </span>        <span class="ID">btn2</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="Number">9</span><span class="Operator">,</span> <span class="String">'Close'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  19 </span></span>
<span class="line"><span class="LineNumber">  20 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">8</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnAdjust</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  21 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">9</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnClose</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  22 </span>        <span class="ID">vbox</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">sld</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_CENTRE</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  23 </span>        <span class="ID">hbox</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">btn1</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">RIGHT</span><span class="Operator">,</span> <span class="Number">10</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  24 </span>        <span class="ID">hbox</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">btn2</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  25 </span>        <span class="ID">vbox</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">hbox</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_CENTRE</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALL</span><span class="Operator">,</span> <span class="Number">20</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  26 </span>        <span class="ID">panel</span><span class="Operator">.</span><span class="ID">SetSizer</span><span class="Operator">(</span><span class="ID">vbox</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  27 </span></span>
<span class="line"><span class="LineNumber">  28 </span>    <span class="ResWord">def</span> <span class="ID">OnAdjust</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  29 </span>        <span class="ID">val</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">sld</span><span class="Operator">.</span><span class="ID">GetValue</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  30 </span></span>
<span class="line"><span class="LineNumber">  31 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetSize</span><span class="Operator">(</span><span class="Operator">(</span><span class="ID">val</span><span class="Operator">*</span><span class="Number">2</span><span class="Operator">,</span> <span class="ID">val</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  32 </span>    <span class="ResWord">def</span> <span class="ID">OnClose</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  33 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Close</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  34 </span></span>
<span class="line"><span class="LineNumber">  35 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  36 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  37 </span>        <span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'slider.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  38 </span>        <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  39 </span>        <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  40 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  41 </span></span>
<span class="line"><span class="LineNumber">  42 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  43 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-2638"></span><p class="line874">In
 this example we have a slider and two buttons. Slider initial position 
is set to 200. The min value is 150, max value is 500. When you click 
adjust button, the frame size is changed. The height is set to value 
chosen by slider, the width is set to 2 x value. <span class="anchor" id="line-2639"></span><span class="anchor" id="line-2640"></span></p><p class="line867"><img alt="slider.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_014.png" title="slider.png"> <span class="anchor" id="line-2641"></span><span class="anchor" id="line-2642"></span></p><p class="line867"><strong>Figure: slider.py</strong> <span class="anchor" id="line-2643"></span><span class="anchor" id="line-2644"></span></p><p class="line867">
</p><h3 id="wx.ListBox">wx.ListBox</h3>
<span class="anchor" id="line-2645"></span><p class="line874">wx.Listbox
 is a widget that consists of a scrolling box and a list of items. User 
can select one or more items from that list. It depends on whether it is
 created as a single or multiple selection box. Selected items are 
marked. <span class="anchor" id="line-2646"></span><span class="anchor" id="line-2647"></span></p><p class="line867"><span class="anchor" id="line-2648"></span><span class="anchor" id="line-2649"></span><span class="anchor" id="line-2650"></span><span class="anchor" id="line-2651"></span><span class="anchor" id="line-2652"></span><span class="anchor" id="line-2653"></span><span class="anchor" id="line-2654"></span><span class="anchor" id="line-2655"></span><span class="anchor" id="line-2656"></span><span class="anchor" id="line-2657"></span><span class="anchor" id="line-2658"></span><span class="anchor" id="line-2659"></span><span class="anchor" id="line-2660"></span><span class="anchor" id="line-2661"></span><span class="anchor" id="line-2662"></span><span class="anchor" id="line-2663"></span><span class="anchor" id="line-2664"></span><span class="anchor" id="line-2665"></span><span class="anchor" id="line-2666"></span><span class="anchor" id="line-2667"></span><span class="anchor" id="line-2668"></span><span class="anchor" id="line-2669"></span><span class="anchor" id="line-2670"></span><span class="anchor" id="line-2671"></span><span class="anchor" id="line-2672"></span><span class="anchor" id="line-2673"></span><span class="anchor" id="line-2674"></span><span class="anchor" id="line-2675"></span><span class="anchor" id="line-2676"></span><span class="anchor" id="line-2677"></span><span class="anchor" id="line-2678"></span><span class="anchor" id="line-2679"></span><span class="anchor" id="line-2680"></span><span class="anchor" id="line-2681"></span><span class="anchor" id="line-2682"></span><span class="anchor" id="line-2683"></span><span class="anchor" id="line-2684"></span><span class="anchor" id="line-2685"></span><span class="anchor" id="line-2686"></span><span class="anchor" id="line-2687"></span><span class="anchor" id="line-2688"></span><span class="anchor" id="line-2689"></span><span class="anchor" id="line-2690"></span><span class="anchor" id="line-2691"></span><span class="anchor" id="line-2692"></span><span class="anchor" id="line-2693"></span><span class="anchor" id="line-2694"></span><span class="anchor" id="line-2695"></span><span class="anchor" id="line-2696"></span><span class="anchor" id="line-2697"></span><span class="anchor" id="line-2698"></span><span class="anchor" id="line-2699"></span><span class="anchor" id="line-2700"></span><span class="anchor" id="line-2701"></span><span class="anchor" id="line-2702"></span><span class="anchor" id="line-2703"></span><span class="anchor" id="line-2704"></span><span class="anchor" id="line-2705"></span><span class="anchor" id="line-2706"></span><span class="anchor" id="line-2707"></span><span class="anchor" id="line-2708"></span><span class="anchor" id="line-2709"></span><span class="anchor" id="line-2710"></span><span class="anchor" id="line-2711"></span><span class="anchor" id="line-2712"></span><span class="anchor" id="line-2713"></span><span class="anchor" id="line-2714"></span><span class="anchor" id="line-2715"></span><span class="anchor" id="line-2716"></span><span class="anchor" id="line-2717"></span><span class="anchor" id="line-2718"></span><span class="anchor" id="line-2719"></span><span class="anchor" id="line-2720"></span><span class="anchor" id="line-2721"></span><span class="anchor" id="line-2722"></span><span class="anchor" id="line-2723"></span><span class="anchor" id="line-2724"></span><span class="anchor" id="line-2725"></span><span class="anchor" id="line-2726"></span><span class="anchor" id="line-2727"></span><span class="anchor" id="line-2728"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-5a4dc34b8671abc9bea0a135cf65fc5127491c68\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-5a4dc34b8671abc9bea0a135cf65fc5127491c68', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-5a4dc34b8671abc9bea0a135cf65fc5127491c68" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span><span class="Comment"># listbox.py</span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   5 </span></span>
<span class="line"><span class="LineNumber">   6 </span><span class="ResWord">from</span> <span class="ID">time</span> <span class="ResWord">import</span> <span class="Operator">*</span></span>
<span class="line"><span class="LineNumber">   7 </span></span>
<span class="line"><span class="LineNumber">   8 </span><span class="ResWord">class</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  10 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">DefaultPosition</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">550</span><span class="Operator">,</span> <span class="Number">350</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  11 </span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">zone_list</span> <span class="Operator">=</span> <span class="Operator">[</span><span class="String">'CET'</span><span class="Operator">,</span> <span class="String">'GMT'</span><span class="Operator">,</span> <span class="String">'MSK'</span><span class="Operator">,</span> <span class="String">'EST'</span><span class="Operator">,</span> <span class="String">'PST'</span><span class="Operator">,</span> <span class="String">'EDT'</span><span class="Operator">]</span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">full_list</span> <span class="Operator">=</span> <span class="Operator">{</span></span>
<span class="line"><span class="LineNumber">  14 </span>            <span class="String">'CET'</span><span class="Operator">:</span> <span class="String">'Central European Time'</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  15 </span>            <span class="String">'GMT'</span><span class="Operator">:</span> <span class="String">'Greenwich Mean Time'</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  16 </span>            <span class="String">'MSK'</span><span class="Operator">:</span> <span class="String">'Moscow Time'</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  17 </span>            <span class="String">'EST'</span><span class="Operator">:</span> <span class="String">'Eastern Standard Time'</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  18 </span>            <span class="String">'PST'</span><span class="Operator">:</span> <span class="String">'Pacific Standard Time'</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  19 </span>            <span class="String">'EDT'</span><span class="Operator">:</span> <span class="String">'Eastern Daylight Time'</span></span>
<span class="line"><span class="LineNumber">  20 </span>        <span class="Operator">}</span></span>
<span class="line"><span class="LineNumber">  21 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">time_diff</span> <span class="Operator">=</span> <span class="Operator">{</span></span>
<span class="line"><span class="LineNumber">  22 </span>            <span class="String">'CET'</span> <span class="Operator">:</span> <span class="Number">1</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  23 </span>            <span class="String">'GMT'</span> <span class="Operator">:</span> <span class="Number">0</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  24 </span>            <span class="String">'MSK'</span><span class="Operator">:</span> <span class="Number">3</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  25 </span>            <span class="String">'EST'</span><span class="Operator">:</span> <span class="Operator">-</span><span class="Number">5</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  26 </span>            <span class="String">'PST'</span><span class="Operator">:</span> <span class="Operator">-</span><span class="Number">8</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  27 </span>            <span class="String">'EDT'</span><span class="Operator">:</span> <span class="Operator">-</span><span class="Number">4</span></span>
<span class="line"><span class="LineNumber">  28 </span>        <span class="Operator">}</span></span>
<span class="line"><span class="LineNumber">  29 </span></span>
<span class="line"><span class="LineNumber">  30 </span>        <span class="ID">vbox</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BoxSizer</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">VERTICAL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  31 </span>        <span class="ID">hbox1</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BoxSizer</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">HORIZONTAL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  32 </span>        <span class="ID">hbox2</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BoxSizer</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">HORIZONTAL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  33 </span>        <span class="ID">hbox3</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BoxSizer</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">HORIZONTAL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  34 </span></span>
<span class="line"><span class="LineNumber">  35 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">timer</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Timer</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  36 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">diff</span> <span class="Operator">=</span> <span class="Number">0</span></span>
<span class="line"><span class="LineNumber">  37 </span>        <span class="ID">panel</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  38 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">time_zones</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ListBox</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="Number">26</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">DefaultPosition</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">170</span><span class="Operator">,</span> <span class="Number">130</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">zone_list</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">LB_SINGLE</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  39 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">time_zones</span><span class="Operator">.</span><span class="ID">SetSelection</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  40 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">text</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TextCtrl</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Central European Time'</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">200</span><span class="Operator">,</span> <span class="Number">130</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">TE_MULTILINE</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  41 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">time</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  42 </span>        <span class="ID">btn</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ID_CLOSE</span><span class="Operator">,</span> <span class="String">'Close'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  43 </span>        <span class="ID">hbox1</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">time_zones</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TOP</span><span class="Operator">,</span> <span class="Number">40</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  44 </span>        <span class="ID">hbox1</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">text</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">LEFT</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TOP</span><span class="Operator">,</span> <span class="Number">40</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  45 </span>        <span class="ID">hbox2</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">time</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_CENTRE</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  46 </span>        <span class="ID">hbox3</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">btn</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_CENTRE</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  47 </span>        <span class="ID">vbox</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">hbox1</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_CENTRE</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  48 </span>        <span class="ID">vbox</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">hbox2</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_CENTRE</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  49 </span>        <span class="ID">vbox</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">hbox3</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_CENTRE</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  50 </span>        <span class="ID">panel</span><span class="Operator">.</span><span class="ID">SetSizer</span><span class="Operator">(</span><span class="ID">vbox</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  51 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">timer</span><span class="Operator">.</span><span class="ID">Start</span><span class="Operator">(</span><span class="Number">100</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  52 </span></span>
<span class="line"><span class="LineNumber">  53 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnClose</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">ID_CLOSE</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  54 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_LISTBOX</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnSelect</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">26</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  55 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_TIMER</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnTimer</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  56 </span></span>
<span class="line"><span class="LineNumber">  57 </span>    <span class="ResWord">def</span> <span class="ID">OnClose</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  58 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Close</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  59 </span></span>
<span class="line"><span class="LineNumber">  60 </span>    <span class="ResWord">def</span> <span class="ID">OnSelect</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  61 </span>        <span class="ID">index</span> <span class="Operator">=</span> <span class="ID">event</span><span class="Operator">.</span><span class="ID">GetSelection</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  62 </span>        <span class="ID">time_zone</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">time_zones</span><span class="Operator">.</span><span class="ID">GetString</span><span class="Operator">(</span><span class="ID">index</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  63 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">diff</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">time_diff</span><span class="Operator">[</span><span class="ID">time_zone</span><span class="Operator">]</span></span>
<span class="line"><span class="LineNumber">  64 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">text</span><span class="Operator">.</span><span class="ID">SetValue</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">full_list</span><span class="Operator">[</span><span class="ID">time_zone</span><span class="Operator">]</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  65 </span></span>
<span class="line"><span class="LineNumber">  66 </span>    <span class="ResWord">def</span> <span class="ID">OnTimer</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  67 </span>        <span class="ID">ct</span> <span class="Operator">=</span> <span class="ID">gmtime</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  68 </span>        <span class="ID">print_time</span> <span class="Operator">=</span> <span class="Operator">(</span><span class="ID">ct</span><span class="Operator">[</span><span class="Number">0</span><span class="Operator">]</span><span class="Operator">,</span> <span class="ID">ct</span><span class="Operator">[</span><span class="Number">1</span><span class="Operator">]</span><span class="Operator">,</span> <span class="ID">ct</span><span class="Operator">[</span><span class="Number">2</span><span class="Operator">]</span><span class="Operator">,</span> <span class="ID">ct</span><span class="Operator">[</span><span class="Number">3</span><span class="Operator">]</span><span class="Operator">+</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">diff</span><span class="Operator">,</span> <span class="ID">ct</span><span class="Operator">[</span><span class="Number">4</span><span class="Operator">]</span><span class="Operator">,</span> <span class="ID">ct</span><span class="Operator">[</span><span class="Number">5</span><span class="Operator">]</span><span class="Operator">,</span> <span class="ID">ct</span><span class="Operator">[</span><span class="Number">6</span><span class="Operator">]</span><span class="Operator">,</span> <span class="ID">ct</span><span class="Operator">[</span><span class="Number">7</span><span class="Operator">]</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  69 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">time</span><span class="Operator">.</span><span class="ID">SetLabel</span><span class="Operator">(</span><span class="ID">strftime</span><span class="Operator">(</span><span class="String">"%H:%M:%S"</span><span class="Operator">,</span> <span class="ID">print_time</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  70 </span></span>
<span class="line"><span class="LineNumber">  71 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  72 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  73 </span>        <span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'listbox.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  74 </span>        <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  75 </span>        <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  76 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  77 </span></span>
<span class="line"><span class="LineNumber">  78 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  79 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-2729"></span><p class="line862">listbox.py example consists of four different widgets.<tt>wx.Listbox</tt>, <tt>wx.TextCtrl</tt>, <tt>wx.StaticText</tt> and <tt>wx.Button</tt>. Widgets are organized with <tt>wx.BoxSizer-s</tt>. <tt>wx.Listbox</tt> has a list of six different world times. These abbreviations are explained in the <tt>wx.TextCtrl</tt>. Current time is displayed in the <tt>wx.StaticText</tt> widget. wx.Timer widget is used to update the time every 100 miliseconds. <span class="anchor" id="line-2730"></span><span class="anchor" id="line-2731"></span></p><p class="line867"><img alt="listbox.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_029.png" title="listbox.png"> <span class="anchor" id="line-2732"></span><span class="anchor" id="line-2733"></span></p><p class="line867"><strong>Figure: listbox.py</strong> <span class="anchor" id="line-2734"></span><span class="anchor" id="line-2735"></span></p><p class="line867">
</p><h3 id="wx.SpinCtrl">wx.SpinCtrl</h3>
<span class="anchor" id="line-2736"></span><p class="line874">This 
widget lets you increment and decrement a value. It has two up and down 
arrow buttons for this purpose. User can enter a value into a box or 
increment/decrement it by these two arrows. <span class="anchor" id="line-2737"></span><span class="anchor" id="line-2738"></span></p><p class="line867"><strong><tt>wx.SpinCtrl&nbsp;styles</tt></strong> <span class="anchor" id="line-2739"></span><span class="anchor" id="line-2740"></span></p><ul><li>wx.SP_ARROW_KEYS <span class="anchor" id="line-2741"></span></li><li>wx.SP_WRAP <span class="anchor" id="line-2742"></span><span class="anchor" id="line-2743"></span></li></ul><div><table><tbody><tr>  <td colspan="2" style="text-align: center;"><p class="line891"><strong><tt>wx.SpinCtrl&nbsp;methods</tt></strong> </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-2744"></span><p class="line891"><tt>integer&nbsp;GetValue()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">get the current value </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-2745"></span><p class="line891"><tt>SetValue(integer&nbsp;value)</tt> </p></td>
  <td><p class="line862">set the current value </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-2746"></span><p class="line891"><tt>SetValueString(string&nbsp;value)</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">something </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-2747"></span><p class="line891"><tt>SetRange(integer&nbsp;min,&nbsp;integer&nbsp;max)</tt> </p></td>
  <td><p class="line862">set the min and max values </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-2748"></span><p class="line891"><tt>integer&nbsp;GetMin()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">get the minimum value </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-2749"></span><p class="line891"><tt>integer&nbsp;GetMax()</tt> </p></td>
  <td><p class="line862">get the maximum value </p></td>
</tr>
</tbody></table></div><span class="anchor" id="line-2750"></span><span class="anchor" id="line-2751"></span><span class="anchor" id="line-2752"></span><p class="line867"><span class="anchor" id="line-2753"></span><span class="anchor" id="line-2754"></span><span class="anchor" id="line-2755"></span><span class="anchor" id="line-2756"></span><span class="anchor" id="line-2757"></span><span class="anchor" id="line-2758"></span><span class="anchor" id="line-2759"></span><span class="anchor" id="line-2760"></span><span class="anchor" id="line-2761"></span><span class="anchor" id="line-2762"></span><span class="anchor" id="line-2763"></span><span class="anchor" id="line-2764"></span><span class="anchor" id="line-2765"></span><span class="anchor" id="line-2766"></span><span class="anchor" id="line-2767"></span><span class="anchor" id="line-2768"></span><span class="anchor" id="line-2769"></span><span class="anchor" id="line-2770"></span><span class="anchor" id="line-2771"></span><span class="anchor" id="line-2772"></span><span class="anchor" id="line-2773"></span><span class="anchor" id="line-2774"></span><span class="anchor" id="line-2775"></span><span class="anchor" id="line-2776"></span><span class="anchor" id="line-2777"></span><span class="anchor" id="line-2778"></span><span class="anchor" id="line-2779"></span><span class="anchor" id="line-2780"></span><span class="anchor" id="line-2781"></span><span class="anchor" id="line-2782"></span><span class="anchor" id="line-2783"></span><span class="anchor" id="line-2784"></span><span class="anchor" id="line-2785"></span><span class="anchor" id="line-2786"></span><span class="anchor" id="line-2787"></span><span class="anchor" id="line-2788"></span><span class="anchor" id="line-2789"></span><span class="anchor" id="line-2790"></span><span class="anchor" id="line-2791"></span><span class="anchor" id="line-2792"></span><span class="anchor" id="line-2793"></span><span class="anchor" id="line-2794"></span><span class="anchor" id="line-2795"></span><span class="anchor" id="line-2796"></span><span class="anchor" id="line-2797"></span><span class="anchor" id="line-2798"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-d80cef03f6b5daaa1bb30cb0e5ee9d3dc25f1b32\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-d80cef03f6b5daaa1bb30cb0e5ee9d3dc25f1b32', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-d80cef03f6b5daaa1bb30cb0e5ee9d3dc25f1b32" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># spinctrl.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ResWord">class</span> <span class="ID">MyDialog</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Dialog</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   8 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Dialog</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">DefaultPosition</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Size</span><span class="Operator">(</span><span class="Number">350</span><span class="Operator">,</span> <span class="Number">310</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  10 </span></span>
<span class="line"><span class="LineNumber">  11 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Convert Fahrenheit temperature to Celsius'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">20</span><span class="Operator">,</span><span class="Number">20</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Fahrenheit: '</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">20</span><span class="Operator">,</span> <span class="Number">80</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Celsius: '</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">20</span><span class="Operator">,</span> <span class="Number">150</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">celsius</span> <span class="Operator">=</span>  <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">150</span><span class="Operator">,</span> <span class="Number">150</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">sc</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">SpinCtrl</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">,</span>  <span class="Operator">(</span><span class="Number">150</span><span class="Operator">,</span> <span class="Number">75</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">60</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">sc</span><span class="Operator">.</span><span class="ID">SetRange</span><span class="Operator">(</span><span class="Operator">-</span><span class="Number">459</span><span class="Operator">,</span> <span class="Number">1000</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  18 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">sc</span><span class="Operator">.</span><span class="ID">SetValue</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  19 </span></span>
<span class="line"><span class="LineNumber">  20 </span>        <span class="ID">compute_btn</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="String">'Compute'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">70</span><span class="Operator">,</span> <span class="Number">250</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  21 </span>        <span class="ID">compute_btn</span><span class="Operator">.</span><span class="ID">SetFocus</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  22 </span>        <span class="ID">clear_btn</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">2</span><span class="Operator">,</span> <span class="String">'Close'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">185</span><span class="Operator">,</span> <span class="Number">250</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  23 </span></span>
<span class="line"><span class="LineNumber">  24 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnCompute</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  25 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnClose</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">2</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  26 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_CLOSE</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnClose</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  27 </span></span>
<span class="line"><span class="LineNumber">  28 </span>    <span class="ResWord">def</span> <span class="ID">OnCompute</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  29 </span>        <span class="ID">fahr</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">sc</span><span class="Operator">.</span><span class="ID">GetValue</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  30 </span>        <span class="ID">cels</span> <span class="Operator">=</span> <span class="ID">round</span><span class="Operator">(</span><span class="Operator">(</span><span class="ID">fahr</span><span class="Operator">-</span><span class="Number">32</span><span class="Operator">)</span><span class="Operator">*</span><span class="Number">5</span><span class="Operator">/</span><span class="Number">9.0</span><span class="Operator">,</span> <span class="Number">2</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  31 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">celsius</span><span class="Operator">.</span><span class="ID">SetLabel</span><span class="Operator">(</span><span class="ID">str</span><span class="Operator">(</span><span class="ID">cels</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  32 </span></span>
<span class="line"><span class="LineNumber">  33 </span>    <span class="ResWord">def</span> <span class="ID">OnClose</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  34 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Destroy</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  35 </span></span>
<span class="line"><span class="LineNumber">  36 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  37 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  38 </span>        <span class="ID">dlg</span> <span class="Operator">=</span> <span class="ID">MyDialog</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'spinctrl.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  39 </span>        <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  40 </span>        <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  41 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  42 </span></span>
<span class="line"><span class="LineNumber">  43 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  44 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-2799"></span><p class="line862">spinctrl.py is a dialog-based script. Our main class inherits from<tt>wx.Dialog</tt> instead of <tt>wx.Frame</tt>.
 The main difference is that we cannot resize the window and we call 
Destroy() method instead of Close(), when we quit the application. 
spinctrl.py script converts Fahrenheit temperature to Celsius. This 
example is very popular and can be found in most programming primer 
books. <span class="anchor" id="line-2800"></span><span class="anchor" id="line-2801"></span></p><p class="line867"><img alt="spinctrl.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_051.png" title="spinctrl.png"> <span class="anchor" id="line-2802"></span><span class="anchor" id="line-2803"></span></p><p class="line867"><strong>Figure spinctrl.py</strong> <span class="anchor" id="line-2804"></span><span class="anchor" id="line-2805"></span></p><p class="line867">
</p><h3 id="wx.ListCtrl">wx.ListCtrl</h3>
<span class="anchor" id="line-2806"></span><p class="line867"><tt>wx.ListCtrl</tt> creates lists in the following formats: <span class="anchor" id="line-2807"></span><span class="anchor" id="line-2808"></span></p><ul><li>report view <span class="anchor" id="line-2809"></span></li><li>list view <span class="anchor" id="line-2810"></span></li><li>icon view <span class="anchor" id="line-2811"></span><span class="anchor" id="line-2812"></span></li></ul><p class="line874">In our example, we key in the states and their capitals and add them into the list widget. We use report view. <span class="anchor" id="line-2813"></span><span class="anchor" id="line-2814"></span></p><p class="line867"><span class="anchor" id="line-2815"></span><span class="anchor" id="line-2816"></span><span class="anchor" id="line-2817"></span><span class="anchor" id="line-2818"></span><span class="anchor" id="line-2819"></span><span class="anchor" id="line-2820"></span><span class="anchor" id="line-2821"></span><span class="anchor" id="line-2822"></span><span class="anchor" id="line-2823"></span><span class="anchor" id="line-2824"></span><span class="anchor" id="line-2825"></span><span class="anchor" id="line-2826"></span><span class="anchor" id="line-2827"></span><span class="anchor" id="line-2828"></span><span class="anchor" id="line-2829"></span><span class="anchor" id="line-2830"></span><span class="anchor" id="line-2831"></span><span class="anchor" id="line-2832"></span><span class="anchor" id="line-2833"></span><span class="anchor" id="line-2834"></span><span class="anchor" id="line-2835"></span><span class="anchor" id="line-2836"></span><span class="anchor" id="line-2837"></span><span class="anchor" id="line-2838"></span><span class="anchor" id="line-2839"></span><span class="anchor" id="line-2840"></span><span class="anchor" id="line-2841"></span><span class="anchor" id="line-2842"></span><span class="anchor" id="line-2843"></span><span class="anchor" id="line-2844"></span><span class="anchor" id="line-2845"></span><span class="anchor" id="line-2846"></span><span class="anchor" id="line-2847"></span><span class="anchor" id="line-2848"></span><span class="anchor" id="line-2849"></span><span class="anchor" id="line-2850"></span><span class="anchor" id="line-2851"></span><span class="anchor" id="line-2852"></span><span class="anchor" id="line-2853"></span><span class="anchor" id="line-2854"></span><span class="anchor" id="line-2855"></span><span class="anchor" id="line-2856"></span><span class="anchor" id="line-2857"></span><span class="anchor" id="line-2858"></span><span class="anchor" id="line-2859"></span><span class="anchor" id="line-2860"></span><span class="anchor" id="line-2861"></span><span class="anchor" id="line-2862"></span><span class="anchor" id="line-2863"></span><span class="anchor" id="line-2864"></span><span class="anchor" id="line-2865"></span><span class="anchor" id="line-2866"></span><span class="anchor" id="line-2867"></span><span class="anchor" id="line-2868"></span><span class="anchor" id="line-2869"></span><span class="anchor" id="line-2870"></span><span class="anchor" id="line-2871"></span><span class="anchor" id="line-2872"></span><span class="anchor" id="line-2873"></span><span class="anchor" id="line-2874"></span><span class="anchor" id="line-2875"></span><span class="anchor" id="line-2876"></span><span class="anchor" id="line-2877"></span><span class="anchor" id="line-2878"></span><span class="anchor" id="line-2879"></span><span class="anchor" id="line-2880"></span><span class="anchor" id="line-2881"></span><span class="anchor" id="line-2882"></span><span class="anchor" id="line-2883"></span><span class="anchor" id="line-2884"></span><span class="anchor" id="line-2885"></span><span class="anchor" id="line-2886"></span><span class="anchor" id="line-2887"></span><span class="anchor" id="line-2888"></span><span class="anchor" id="line-2889"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-f5281d5e2e8aa73407dd27ef352df14fd2282592\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-f5281d5e2e8aa73407dd27ef352df14fd2282592', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-f5281d5e2e8aa73407dd27ef352df14fd2282592" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># capitals.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ResWord">class</span> <span class="ID">MyDialog</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Dialog</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   8 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Dialog</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">600</span><span class="Operator">,</span><span class="Number">500</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">DEFAULT_DIALOG_STYLE</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  10 </span></span>
<span class="line"><span class="LineNumber">  11 </span>        <span class="ID">hbox</span>  <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BoxSizer</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">HORIZONTAL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">vbox1</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BoxSizer</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">VERTICAL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">vbox2</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BoxSizer</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">VERTICAL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">vbox3</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">GridSizer</span><span class="Operator">(</span><span class="Number">2</span><span class="Operator">,</span><span class="Number">2</span><span class="Operator">,</span><span class="Number">0</span><span class="Operator">,</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">vbox4</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BoxSizer</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">VERTICAL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span>        <span class="ID">pnl1</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">SIMPLE_BORDER</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="ID">pnl2</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">SIMPLE_BORDER</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  18 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">lc</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ListCtrl</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">LC_REPORT</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  19 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">lc</span><span class="Operator">.</span><span class="ID">InsertColumn</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">,</span> <span class="String">'State'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  20 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">lc</span><span class="Operator">.</span><span class="ID">InsertColumn</span><span class="Operator">(</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Capital'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  21 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">lc</span><span class="Operator">.</span><span class="ID">SetColumnWidth</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">,</span> <span class="Number">140</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  22 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">lc</span><span class="Operator">.</span><span class="ID">SetColumnWidth</span><span class="Operator">(</span><span class="Number">1</span><span class="Operator">,</span> <span class="Number">153</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  23 </span>        <span class="ID">vbox1</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">pnl1</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALL</span><span class="Operator">,</span> <span class="Number">3</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  24 </span>        <span class="ID">vbox1</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">pnl2</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALL</span><span class="Operator">,</span> <span class="Number">3</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  25 </span>        <span class="ID">vbox2</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">lc</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALL</span><span class="Operator">,</span> <span class="Number">3</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  26 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tc1</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TextCtrl</span><span class="Operator">(</span><span class="ID">pnl1</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  27 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tc2</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TextCtrl</span><span class="Operator">(</span><span class="ID">pnl1</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  28 </span>        <span class="ID">vbox3</span><span class="Operator">.</span><span class="ID">AddMany</span><span class="Operator">(</span><span class="Operator">[</span> <span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">pnl1</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'State'</span><span class="Operator">)</span><span class="Operator">,</span><span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_CENTER</span><span class="Operator">)</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  29 </span>                        <span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">tc1</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_LEFT</span><span class="Operator">|</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_CENTER_VERTICAL</span><span class="Operator">)</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  30 </span>                        <span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">pnl1</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Capital'</span><span class="Operator">)</span><span class="Operator">,</span><span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_CENTER_HORIZONTAL</span><span class="Operator">)</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  31 </span>                        <span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">tc2</span><span class="Operator">,</span><span class="Number">0</span><span class="Operator">)</span><span class="Operator">]</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  32 </span>        <span class="ID">pnl1</span><span class="Operator">.</span><span class="ID">SetSizer</span><span class="Operator">(</span><span class="ID">vbox3</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  33 </span>        <span class="ID">vbox4</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">pnl2</span><span class="Operator">,</span> <span class="Number">10</span><span class="Operator">,</span> <span class="String">'Add'</span><span class="Operator">)</span><span class="Operator">,</span>   <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_CENTER</span><span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TOP</span><span class="Operator">,</span> <span class="Number">45</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  34 </span>        <span class="ID">vbox4</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">pnl2</span><span class="Operator">,</span> <span class="Number">11</span><span class="Operator">,</span> <span class="String">'Remove'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_CENTER</span><span class="Operator">|</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">TOP</span><span class="Operator">,</span> <span class="Number">15</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  35 </span>        <span class="ID">vbox4</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">pnl2</span><span class="Operator">,</span> <span class="Number">12</span><span class="Operator">,</span> <span class="String">'Clear'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_CENTER</span><span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TOP</span><span class="Operator">,</span> <span class="Number">15</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  36 </span>        <span class="ID">vbox4</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">pnl2</span><span class="Operator">,</span> <span class="Number">13</span><span class="Operator">,</span> <span class="String">'Close'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_CENTER</span><span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TOP</span><span class="Operator">,</span> <span class="Number">15</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  37 </span>        <span class="ID">pnl2</span><span class="Operator">.</span><span class="ID">SetSizer</span><span class="Operator">(</span><span class="ID">vbox4</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  38 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span> <span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnAdd</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">10</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  39 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span> <span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnRemove</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">11</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  40 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span> <span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnClear</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">12</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  41 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span> <span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnClose</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">13</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  42 </span>        <span class="ID">hbox</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">vbox1</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  43 </span>        <span class="ID">hbox</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">vbox2</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  44 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetSizer</span><span class="Operator">(</span><span class="ID">hbox</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  45 </span></span>
<span class="line"><span class="LineNumber">  46 </span>    <span class="ResWord">def</span> <span class="ID">OnAdd</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  47 </span>        <span class="ResWord">if</span> <span class="ResWord">not</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tc1</span><span class="Operator">.</span><span class="ID">GetValue</span><span class="Operator">(</span><span class="Operator">)</span> <span class="ResWord">or</span> <span class="ResWord">not</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tc2</span><span class="Operator">.</span><span class="ID">GetValue</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  48 </span>            <span class="ResWord">return</span></span>
<span class="line"><span class="LineNumber">  49 </span>        <span class="ID">num_items</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">lc</span><span class="Operator">.</span><span class="ID">GetItemCount</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  50 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">lc</span><span class="Operator">.</span><span class="ID">InsertStringItem</span><span class="Operator">(</span><span class="ID">num_items</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tc1</span><span class="Operator">.</span><span class="ID">GetValue</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  51 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">lc</span><span class="Operator">.</span><span class="ID">SetStringItem</span><span class="Operator">(</span><span class="ID">num_items</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tc2</span><span class="Operator">.</span><span class="ID">GetValue</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  52 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tc1</span><span class="Operator">.</span><span class="ID">Clear</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  53 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tc2</span><span class="Operator">.</span><span class="ID">Clear</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  54 </span></span>
<span class="line"><span class="LineNumber">  55 </span>    <span class="ResWord">def</span> <span class="ID">OnRemove</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  56 </span>        <span class="ID">index</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">lc</span><span class="Operator">.</span><span class="ID">GetFocusedItem</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  57 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">lc</span><span class="Operator">.</span><span class="ID">DeleteItem</span><span class="Operator">(</span><span class="ID">index</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  58 </span></span>
<span class="line"><span class="LineNumber">  59 </span>    <span class="ResWord">def</span> <span class="ID">OnClose</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  60 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Close</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  61 </span></span>
<span class="line"><span class="LineNumber">  62 </span>    <span class="ResWord">def</span> <span class="ID">OnClear</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  63 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">lc</span><span class="Operator">.</span><span class="ID">DeleteAllItems</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  64 </span></span>
<span class="line"><span class="LineNumber">  65 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  66 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  67 </span>        <span class="ID">dia</span> <span class="Operator">=</span> <span class="ID">MyDialog</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'capitals.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  68 </span>        <span class="ID">dia</span><span class="Operator">.</span><span class="ID">ShowModal</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  69 </span>        <span class="ID">dia</span><span class="Operator">.</span><span class="ID">Destroy</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  70 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  71 </span></span>
<span class="line"><span class="LineNumber">  72 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  73 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-2890"></span><p class="line867"><img alt="capitals1.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_013.png" title="capitals1.png"> <span class="anchor" id="line-2891"></span><span class="anchor" id="line-2892"></span></p><p class="line867"><strong>Figure: capitals.py</strong> <span class="anchor" id="line-2893"></span><span class="anchor" id="line-2894"></span></p><p class="line867">
</p><h3 id="wx.SplitterWindow">wx.SplitterWindow</h3>
<span class="anchor" id="line-2895"></span><p class="line874">This 
widget enables to split the main area of an application into parts. The 
user can dynamically resize those parts with the mouse pointer. Such a 
solution can be seen in mail clients (evolution) or in burning software 
(k3b). You can split an area vertically or horizontally. <span class="anchor" id="line-2896"></span><span class="anchor" id="line-2897"></span></p><p class="line867"><span class="anchor" id="line-2898"></span><span class="anchor" id="line-2899"></span><span class="anchor" id="line-2900"></span><span class="anchor" id="line-2901"></span><span class="anchor" id="line-2902"></span><span class="anchor" id="line-2903"></span><span class="anchor" id="line-2904"></span><span class="anchor" id="line-2905"></span><span class="anchor" id="line-2906"></span><span class="anchor" id="line-2907"></span><span class="anchor" id="line-2908"></span><span class="anchor" id="line-2909"></span><span class="anchor" id="line-2910"></span><span class="anchor" id="line-2911"></span><span class="anchor" id="line-2912"></span><span class="anchor" id="line-2913"></span><span class="anchor" id="line-2914"></span><span class="anchor" id="line-2915"></span><span class="anchor" id="line-2916"></span><span class="anchor" id="line-2917"></span><span class="anchor" id="line-2918"></span><span class="anchor" id="line-2919"></span><span class="anchor" id="line-2920"></span><span class="anchor" id="line-2921"></span><span class="anchor" id="line-2922"></span><span class="anchor" id="line-2923"></span><span class="anchor" id="line-2924"></span><span class="anchor" id="line-2925"></span><span class="anchor" id="line-2926"></span><span class="anchor" id="line-2927"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-defafb93b19d1eb6076b4ebe0f77c00d44dcf69b\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-defafb93b19d1eb6076b4ebe0f77c00d44dcf69b', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-defafb93b19d1eb6076b4ebe0f77c00d44dcf69b" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span><span class="Comment"># splitterwindow.py</span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"></span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="ResWord">class</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   5 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   6 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">DefaultPosition</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Size</span><span class="Operator">(</span><span class="Number">350</span><span class="Operator">,</span> <span class="Number">300</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">   7 </span></span>
<span class="line"><span class="LineNumber">   8 </span>        <span class="ID">splitter</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">SplitterWindow</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">   9 </span>        <span class="ID">panel1</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">splitter</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  10 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">panel1</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  11 </span>                    <span class="String">"Whether you think that you can, or that you can't, you are usually right."</span></span>
<span class="line"><span class="LineNumber">  12 </span>                    <span class="String">"\n\n Henry Ford"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  13 </span>            <span class="Operator">(</span><span class="Number">100</span><span class="Operator">,</span><span class="Number">100</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_CENTRE</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">panel1</span><span class="Operator">.</span><span class="ID">SetBackgroundColour</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">LIGHT_GREY</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">panel2</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">splitter</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span>        <span class="ID">panel2</span><span class="Operator">.</span><span class="ID">SetBackgroundColour</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">WHITE</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="ID">splitter</span><span class="Operator">.</span><span class="ID">SplitVertically</span><span class="Operator">(</span><span class="ID">panel1</span><span class="Operator">,</span> <span class="ID">panel2</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  18 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  19 </span></span>
<span class="line"><span class="LineNumber">  20 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  21 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  22 </span>        <span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'splitterwindow.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  23 </span>        <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  24 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetTopWindow</span><span class="Operator">(</span><span class="ID">frame</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  25 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  26 </span></span>
<span class="line"><span class="LineNumber">  27 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  28 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-2928"></span><p class="line867">
</p><h3 id="wx.ScrolledWindow">wx.ScrolledWindow</h3>
<span class="anchor" id="line-2929"></span><p class="line874">This is 
one of the container widgets. It can be useful, when we have a larger 
area than a window can display. In our example, we demonstrate such a 
case. We place a large image into our window. When the window is smaller
 than  our image, Scrollbars are displayed automatically. <span class="anchor" id="line-2930"></span></p><div><table><tbody><tr>  <td colspan="2" style="text-align: center;"><p class="line891"><strong><tt>wx.ScrolledWindow&nbsp;methods</tt></strong> </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-2931"></span><p class="line891"><tt>SetScrollbars()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862"> set scrollbars for a window </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-2932"></span><p class="line891"><tt>Scroll(int&nbsp;x,&nbsp;int&nbsp;y)</tt> </p></td>
  <td><p class="line862"> scroll a window </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-2933"></span><p class="line891"><tt>int&nbsp;GetScrollPageSize(int&nbsp;orient)</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862"> get the scroll page size</p></td>
</tr>
<tr>  <td><span class="anchor" id="line-2934"></span><p class="line891"><tt>SetScrollPageSize(int&nbsp;orient,&nbsp;int&nbsp;pageSize)</tt> </p></td>
  <td><p class="line862"> set the scroll page size </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-2935"></span><p class="line891"><tt>SetScrollRate(int&nbsp;xstep,&nbsp;int&nbsp;ystep)</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862"> set scrolling rate</p></td>
</tr>
<tr>  <td><span class="anchor" id="line-2936"></span><p class="line891"><tt>wx.Size&nbsp;GetScrollPixelsPerUnit()</tt> </p></td>
  <td><p class="line862"> get the size of one logical unit in physical units </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-2937"></span><p class="line891"><tt>SetScrollRate(int&nbsp;xstep,&nbsp;int&nbsp;ystep)</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862"> set scrolling rate</p></td>
</tr>
<tr>  <td><span class="anchor" id="line-2938"></span><p class="line891"><tt>EnableScrolling(bool&nbsp;x,&nbsp;bool&nbsp;y)</tt> </p></td>
  <td><p class="line862"> enable or disable scrolling </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-2939"></span><p class="line891"><tt>wxPoint&nbsp;GetViewStart()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862"> get the view start </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-2940"></span><p class="line891"><tt>SetTargetWindow(wx.Window&nbsp;target)</tt> </p></td>
  <td><p class="line862"> set the target window for scrolling </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-2941"></span><p class="line891"><tt>wx.Window&nbsp;GetTargetWindow()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862"> get the scrolling target window </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-2942"></span><p class="line891"><tt>AdjustScrollbars()</tt> </p></td>
  <td><p class="line862"> adjust scrollbars </p></td>
</tr>
</tbody></table></div><span class="anchor" id="line-2943"></span><span class="anchor" id="line-2944"></span><span class="anchor" id="line-2945"></span><span class="anchor" id="line-2946"></span><span class="anchor" id="line-2947"></span><p class="line867"><span class="anchor" id="line-2948"></span><span class="anchor" id="line-2949"></span><span class="anchor" id="line-2950"></span><span class="anchor" id="line-2951"></span><span class="anchor" id="line-2952"></span><span class="anchor" id="line-2953"></span><span class="anchor" id="line-2954"></span><span class="anchor" id="line-2955"></span><span class="anchor" id="line-2956"></span><span class="anchor" id="line-2957"></span><span class="anchor" id="line-2958"></span><span class="anchor" id="line-2959"></span><span class="anchor" id="line-2960"></span><span class="anchor" id="line-2961"></span><span class="anchor" id="line-2962"></span><span class="anchor" id="line-2963"></span><span class="anchor" id="line-2964"></span><span class="anchor" id="line-2965"></span><span class="anchor" id="line-2966"></span><span class="anchor" id="line-2967"></span><span class="anchor" id="line-2968"></span><span class="anchor" id="line-2969"></span><span class="anchor" id="line-2970"></span><span class="anchor" id="line-2971"></span><span class="anchor" id="line-2972"></span><span class="anchor" id="line-2973"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-91602b2442f8290ac4d91c227cce4c007dc7a967\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-91602b2442f8290ac4d91c227cce4c007dc7a967', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-91602b2442f8290ac4d91c227cce4c007dc7a967" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># myscrolledwindow.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ResWord">class</span> <span class="ID">MyScrolledWindow</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   8 </span>   <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>       <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">500</span><span class="Operator">,</span> <span class="Number">400</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  10 </span></span>
<span class="line"><span class="LineNumber">  11 </span>       <span class="ID">sw</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ScrolledWindow</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  12 </span>       <span class="ID">bmp</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Image</span><span class="Operator">(</span><span class="String">'aliens.jpg'</span><span class="Operator">,</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">BITMAP_TYPE_JPEG</span><span class="Operator">)</span><span class="Operator">.</span><span class="ID">ConvertToBitmap</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span>       <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticBitmap</span><span class="Operator">(</span><span class="ID">sw</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">bmp</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>       <span class="ID">sw</span><span class="Operator">.</span><span class="ID">SetScrollbars</span><span class="Operator">(</span><span class="Number">20</span><span class="Operator">,</span><span class="Number">20</span><span class="Operator">,</span><span class="Number">55</span><span class="Operator">,</span><span class="Number">40</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span></span>
<span class="line"><span class="LineNumber">  16 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  17 </span>   <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  18 </span>       <span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">MyScrolledWindow</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Aliens'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  19 </span>       <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  20 </span>       <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  21 </span>       <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  22 </span></span>
<span class="line"><span class="LineNumber">  23 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  24 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-2974"></span><p class="line867"><img alt="scrolledwindow.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_046.png" title="scrolledwindow.png"> <span class="anchor" id="line-2975"></span><span class="anchor" id="line-2976"></span></p><p class="line867">
</p><h3 id="wx.TreeCtrl">wx.TreeCtrl</h3>
<span class="anchor" id="line-2977"></span><p class="line867"><tt>wx.TreeCtrl</tt> displays data in a hierarchy. <span class="anchor" id="line-2978"></span><span class="anchor" id="line-2979"></span></p><p class="line867"><span class="anchor" id="line-2980"></span><span class="anchor" id="line-2981"></span><span class="anchor" id="line-2982"></span><span class="anchor" id="line-2983"></span><span class="anchor" id="line-2984"></span><span class="anchor" id="line-2985"></span><span class="anchor" id="line-2986"></span><span class="anchor" id="line-2987"></span><span class="anchor" id="line-2988"></span><span class="anchor" id="line-2989"></span><span class="anchor" id="line-2990"></span><span class="anchor" id="line-2991"></span><span class="anchor" id="line-2992"></span><span class="anchor" id="line-2993"></span><span class="anchor" id="line-2994"></span><span class="anchor" id="line-2995"></span><span class="anchor" id="line-2996"></span><span class="anchor" id="line-2997"></span><span class="anchor" id="line-2998"></span><span class="anchor" id="line-2999"></span><span class="anchor" id="line-3000"></span><span class="anchor" id="line-3001"></span><span class="anchor" id="line-3002"></span><span class="anchor" id="line-3003"></span><span class="anchor" id="line-3004"></span><span class="anchor" id="line-3005"></span><span class="anchor" id="line-3006"></span><span class="anchor" id="line-3007"></span><span class="anchor" id="line-3008"></span><span class="anchor" id="line-3009"></span><span class="anchor" id="line-3010"></span><span class="anchor" id="line-3011"></span><span class="anchor" id="line-3012"></span><span class="anchor" id="line-3013"></span><span class="anchor" id="line-3014"></span><span class="anchor" id="line-3015"></span><span class="anchor" id="line-3016"></span><span class="anchor" id="line-3017"></span><span class="anchor" id="line-3018"></span><span class="anchor" id="line-3019"></span><span class="anchor" id="line-3020"></span><span class="anchor" id="line-3021"></span><span class="anchor" id="line-3022"></span><span class="anchor" id="line-3023"></span><span class="anchor" id="line-3024"></span><span class="anchor" id="line-3025"></span><span class="anchor" id="line-3026"></span><span class="anchor" id="line-3027"></span><span class="anchor" id="line-3028"></span><span class="anchor" id="line-3029"></span><span class="anchor" id="line-3030"></span><span class="anchor" id="line-3031"></span><span class="anchor" id="line-3032"></span><span class="anchor" id="line-3033"></span><span class="anchor" id="line-3034"></span><span class="anchor" id="line-3035"></span><span class="anchor" id="line-3036"></span><span class="anchor" id="line-3037"></span><span class="anchor" id="line-3038"></span><span class="anchor" id="line-3039"></span><span class="anchor" id="line-3040"></span><span class="anchor" id="line-3041"></span><span class="anchor" id="line-3042"></span><span class="anchor" id="line-3043"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-fa6f17b322caf9bcfe031e6985f3e1df8a1834ff\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-fa6f17b322caf9bcfe031e6985f3e1df8a1834ff', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-fa6f17b322caf9bcfe031e6985f3e1df8a1834ff" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># treectrl.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ResWord">class</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   8 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">DefaultPosition</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Size</span><span class="Operator">(</span><span class="Number">450</span><span class="Operator">,</span> <span class="Number">350</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  10 </span></span>
<span class="line"><span class="LineNumber">  11 </span>        <span class="ID">hbox</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BoxSizer</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">HORIZONTAL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">vbox</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BoxSizer</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">VERTICAL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">panel1</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">panel2</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span></span>
<span class="line"><span class="LineNumber">  16 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TreeCtrl</span><span class="Operator">(</span><span class="ID">panel1</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">DefaultPosition</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span><span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TR_HIDE_ROOT</span><span class="Operator">|</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">TR_HAS_BUTTONS</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="ID">root</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">AddRoot</span><span class="Operator">(</span><span class="String">'Programmer'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  18 </span>        <span class="ID">os</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">root</span><span class="Operator">,</span> <span class="String">'Operating Systems'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  19 </span>        <span class="ID">pl</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">root</span><span class="Operator">,</span> <span class="String">'Programming Languages'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  20 </span>        <span class="ID">tk</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">root</span><span class="Operator">,</span> <span class="String">'Toolkits'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  21 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">os</span><span class="Operator">,</span> <span class="String">'Linux'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  22 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">os</span><span class="Operator">,</span> <span class="String">'FreeBSD'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  23 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">os</span><span class="Operator">,</span> <span class="String">'OpenBSD'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  24 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">os</span><span class="Operator">,</span> <span class="String">'NetBSD'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  25 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">os</span><span class="Operator">,</span> <span class="String">'Solaris'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  26 </span>        <span class="ID">cl</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">pl</span><span class="Operator">,</span> <span class="String">'Compiled languages'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  27 </span>        <span class="ID">sl</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">pl</span><span class="Operator">,</span> <span class="String">'Scripting languages'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  28 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">cl</span><span class="Operator">,</span> <span class="String">'Java'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  29 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">cl</span><span class="Operator">,</span> <span class="String">'C++'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  30 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">cl</span><span class="Operator">,</span> <span class="String">'C'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  31 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">cl</span><span class="Operator">,</span> <span class="String">'Pascal'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  32 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">sl</span><span class="Operator">,</span> <span class="String">'Python'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  33 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">sl</span><span class="Operator">,</span> <span class="String">'Ruby'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  34 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">sl</span><span class="Operator">,</span> <span class="String">'Tcl'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  35 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">sl</span><span class="Operator">,</span> <span class="String">'PHP'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  36 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">tk</span><span class="Operator">,</span> <span class="String">'Qt'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  37 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">tk</span><span class="Operator">,</span> <span class="String">'MFC'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  38 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">tk</span><span class="Operator">,</span> <span class="String">'wxPython'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  39 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">tk</span><span class="Operator">,</span> <span class="String">'GTK+'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  40 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">tk</span><span class="Operator">,</span> <span class="String">'Swing'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  41 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_TREE_SEL_CHANGED</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnSelChanged</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  42 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">display</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">panel2</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">,</span><span class="Operator">(</span><span class="Number">10</span><span class="Operator">,</span><span class="Number">10</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_CENTRE</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  43 </span>        <span class="ID">vbox</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  44 </span>        <span class="ID">hbox</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">panel1</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  45 </span>        <span class="ID">hbox</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">panel2</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  46 </span>        <span class="ID">panel1</span><span class="Operator">.</span><span class="ID">SetSizer</span><span class="Operator">(</span><span class="ID">vbox</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  47 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetSizer</span><span class="Operator">(</span><span class="ID">hbox</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  48 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  49 </span></span>
<span class="line"><span class="LineNumber">  50 </span>    <span class="ResWord">def</span> <span class="ID">OnSelChanged</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  51 </span>        <span class="ID">item</span> <span class="Operator">=</span>  <span class="ID">event</span><span class="Operator">.</span><span class="ID">GetItem</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  52 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">display</span><span class="Operator">.</span><span class="ID">SetLabel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">GetItemText</span><span class="Operator">(</span><span class="ID">item</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  53 </span></span>
<span class="line"><span class="LineNumber">  54 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  55 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  56 </span>        <span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'treectrl.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  57 </span>        <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  58 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetTopWindow</span><span class="Operator">(</span><span class="ID">frame</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  59 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  60 </span></span>
<span class="line"><span class="LineNumber">  61 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  62 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-3044"></span><p class="line874">First of all we must create a root item. <span class="anchor" id="line-3045"></span><span class="anchor" id="line-3046"></span></p><p class="line867"><span class="anchor" id="line-3047"></span><span class="anchor" id="line-3048"></span></p><pre>root = self.tree.AddRoot('Programmer')</pre><span class="anchor" id="line-3049"></span><p class="line874">In our case, root item will not be displayed, because we used wx.TR_HIDE_ROOT flag in our constructor. <span class="anchor" id="line-3050"></span><span class="anchor" id="line-3051"></span></p><p class="line867"><span class="anchor" id="line-3052"></span><span class="anchor" id="line-3053"></span></p><pre>self.tree = wx.TreeCtrl(panel1, 1, wx.DefaultPosition, (-1,-1), wx.TR_HIDE_ROOT|wx.TR_HAS_BUTTONS)</pre><span class="anchor" id="line-3054"></span><p class="line862">We add items to the root item with<tt>AppendItem()</tt> method. <span class="anchor" id="line-3055"></span><span class="anchor" id="line-3056"></span></p><p class="line867"><span class="anchor" id="line-3057"></span><span class="anchor" id="line-3058"></span><span class="anchor" id="line-3059"></span><span class="anchor" id="line-3060"></span></p><pre>os = self.tree.AppendItem(root, 'Operating Systems')
pl = self.tree.AppendItem(root, 'Programming Languages')
tk = self.tree.AppendItem(root, 'Toolkits')</pre><span class="anchor" id="line-3061"></span><p class="line874">We can similarly create several levels by simply adding items to existing items. <span class="anchor" id="line-3062"></span><span class="anchor" id="line-3063"></span></p><p class="line874">We catch events with wx.EVT_TREE_SEL_CHANGED() event handler. <span class="anchor" id="line-3064"></span><span class="anchor" id="line-3065"></span></p><p class="line867"><span class="anchor" id="line-3066"></span><span class="anchor" id="line-3067"></span></p><pre>wx.EVT_TREE_SEL_CHANGED(self.tree, 1, self.OnSelChanged)</pre><span class="anchor" id="line-3068"></span><p class="line874">Various constructor style flags: <span class="anchor" id="line-3069"></span><span class="anchor" id="line-3070"></span></p><ul><li>TR_NO_BUTTONS <span class="anchor" id="line-3071"></span></li><li>TR_HAS_BUTTONS <span class="anchor" id="line-3072"></span></li><li>TR_NO_LINES <span class="anchor" id="line-3073"></span></li><li>TR_LINES_AT_ROOT <span class="anchor" id="line-3074"></span></li><li>TR_SINGLE <span class="anchor" id="line-3075"></span></li><li>TR_MULTIPLE <span class="anchor" id="line-3076"></span></li><li>TR_EXTENDED <span class="anchor" id="line-3077"></span></li><li>TR_HAS_VARIABLE_ROW_HEIGHT <span class="anchor" id="line-3078"></span></li><li>TR_EDIT_LABELS <span class="anchor" id="line-3079"></span></li><li>TR_HIDE_ROOT <span class="anchor" id="line-3080"></span></li><li>TR_ROW_LINES <span class="anchor" id="line-3081"></span></li><li>TR_FULL_ROW_HIGHLIGHT <span class="anchor" id="line-3082"></span></li><li>TR_DEFAULT_STYLE <span class="anchor" id="line-3083"></span></li><li>TR_TWIST_BUTTONS <span class="anchor" id="line-3084"></span></li><li>TR_MAC_BUTTONS <span class="anchor" id="line-3085"></span></li><li>TR_AQUA_BUTTONS <span class="anchor" id="line-3086"></span><span class="anchor" id="line-3087"></span></li></ul><p class="line867"><img alt="treecontrol.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_034.png" title="treecontrol.png"> <span class="anchor" id="line-3088"></span><span class="anchor" id="line-3089"></span></p><p class="line867"><strong>Figure: treectrl.py</strong> <span class="anchor" id="line-3090"></span><span class="anchor" id="line-3091"></span></p><p class="line867">
</p><h3 id="wx.Notebook">wx.Notebook</h3>
<span class="anchor" id="line-3092"></span><p class="line874">wx.Notebook widget joins multiple windows with corresponding tabs. <span class="anchor" id="line-3093"></span><span class="anchor" id="line-3094"></span></p><p class="line874">You can position the Notebook widget using the following style flags: <span class="anchor" id="line-3095"></span><span class="anchor" id="line-3096"></span></p><ul><li>wx.NB_LEFT <span class="anchor" id="line-3097"></span></li><li>wx.NB_RIGHT <span class="anchor" id="line-3098"></span></li><li>wx.NB_TOP <span class="anchor" id="line-3099"></span></li><li>wx.NB_BOTTOM <span class="anchor" id="line-3100"></span><span class="anchor" id="line-3101"></span></li></ul><p class="line862">The default position is wx.NB_TOP.<br>
 <br>
 <span class="anchor" id="line-3102"></span></p><div><table><tbody><tr>  <td colspan="2" style="text-align: center;"><p class="line891"><strong><tt>wx.Notebook&nbsp;methods</tt></strong> </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-3103"></span><p class="line891"><tt>integer&nbsp;GetRowCount()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">get the number of rows </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-3104"></span><p class="line891"><tt>SetPadding(wx.Size&nbsp;padding)</tt> </p></td>
  <td><p class="line862">set the amount of space around each page's icon and label </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-3105"></span><p class="line891"><tt>SetTabSize(wx.Size&nbsp;size)</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">set the tab size </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-3106"></span><p class="line891"><tt>(tab,&nbsp;where)&nbsp;HitTest(wx.Point&nbsp;point)</tt> </p></td>
  <td><p class="line862">return the tab which is hit </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-3107"></span><p class="line891"><tt>wx.Size&nbsp;CalcSizeFromPage(wx.Size&nbsp;size)</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">something </p></td>
</tr>
</tbody></table></div><span class="anchor" id="line-3108"></span><span class="anchor" id="line-3109"></span><span class="anchor" id="line-3110"></span><span class="anchor" id="line-3111"></span><span class="anchor" id="line-3112"></span><p class="line874">add bookcontrolbase methods where return value of the <span class="anchor" id="line-3113"></span><span class="anchor" id="line-3114"></span></p><p class="line867"><tt>HitTest()</tt> method can be one of: <span class="anchor" id="line-3115"></span><span class="anchor" id="line-3116"></span></p><ul><li>wx.NB_HITTEST_NOWHERE <span class="anchor" id="line-3117"></span></li><li>wx.NB_HITTEST_ONITEM <span class="anchor" id="line-3118"></span><span class="anchor" id="line-3119"></span></li></ul><p class="line874">In our example, we mimic the look of a spreadsheet. <span class="anchor" id="line-3120"></span><span class="anchor" id="line-3121"></span></p><p class="line867"><span class="anchor" id="line-3122"></span><span class="anchor" id="line-3123"></span><span class="anchor" id="line-3124"></span><span class="anchor" id="line-3125"></span><span class="anchor" id="line-3126"></span><span class="anchor" id="line-3127"></span><span class="anchor" id="line-3128"></span><span class="anchor" id="line-3129"></span><span class="anchor" id="line-3130"></span><span class="anchor" id="line-3131"></span><span class="anchor" id="line-3132"></span><span class="anchor" id="line-3133"></span><span class="anchor" id="line-3134"></span><span class="anchor" id="line-3135"></span><span class="anchor" id="line-3136"></span><span class="anchor" id="line-3137"></span><span class="anchor" id="line-3138"></span><span class="anchor" id="line-3139"></span><span class="anchor" id="line-3140"></span><span class="anchor" id="line-3141"></span><span class="anchor" id="line-3142"></span><span class="anchor" id="line-3143"></span><span class="anchor" id="line-3144"></span><span class="anchor" id="line-3145"></span><span class="anchor" id="line-3146"></span><span class="anchor" id="line-3147"></span><span class="anchor" id="line-3148"></span><span class="anchor" id="line-3149"></span><span class="anchor" id="line-3150"></span><span class="anchor" id="line-3151"></span><span class="anchor" id="line-3152"></span><span class="anchor" id="line-3153"></span><span class="anchor" id="line-3154"></span><span class="anchor" id="line-3155"></span><span class="anchor" id="line-3156"></span><span class="anchor" id="line-3157"></span><span class="anchor" id="line-3158"></span><span class="anchor" id="line-3159"></span><span class="anchor" id="line-3160"></span><span class="anchor" id="line-3161"></span><span class="anchor" id="line-3162"></span><span class="anchor" id="line-3163"></span><span class="anchor" id="line-3164"></span><span class="anchor" id="line-3165"></span><span class="anchor" id="line-3166"></span><span class="anchor" id="line-3167"></span><span class="anchor" id="line-3168"></span><span class="anchor" id="line-3169"></span><span class="anchor" id="line-3170"></span><span class="anchor" id="line-3171"></span><span class="anchor" id="line-3172"></span><span class="anchor" id="line-3173"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-858efd9b6771e842b5ac14d7941bff1a7aa73dca\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-858efd9b6771e842b5ac14d7941bff1a7aa73dca', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-858efd9b6771e842b5ac14d7941bff1a7aa73dca" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># notebook.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span><span class="ResWord">import</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">lib</span><span class="Operator">.</span><span class="ID">sheet</span> <span class="ResWord">as</span> <span class="ID">sheet</span></span>
<span class="line"><span class="LineNumber">   7 </span></span>
<span class="line"><span class="LineNumber">   8 </span><span class="ResWord">class</span> <span class="ID">MySheet</span><span class="Operator">(</span><span class="ID">sheet</span><span class="Operator">.</span><span class="ID">CSheet</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  10 </span>        <span class="ID">sheet</span><span class="Operator">.</span><span class="ID">CSheet</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  11 </span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetLabelBackgroundColour</span><span class="Operator">(</span><span class="String">'#DBD4D4'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetNumberRows</span><span class="Operator">(</span><span class="Number">50</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetNumberCols</span><span class="Operator">(</span><span class="Number">50</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span></span>
<span class="line"><span class="LineNumber">  16 </span><span class="ResWord">class</span> <span class="ID">Notebook</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  17 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  18 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">600</span><span class="Operator">,</span> <span class="Number">500</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  19 </span></span>
<span class="line"><span class="LineNumber">  20 </span>        <span class="ID">menubar</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MenuBar</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  21 </span>        <span class="ID">file</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Menu</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  22 </span>        <span class="ID">file</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="Number">101</span><span class="Operator">,</span> <span class="String">'Quit'</span><span class="Operator">,</span> <span class="String">''</span> <span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  23 </span>        <span class="ID">menubar</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="ID">file</span><span class="Operator">,</span> <span class="String">"&amp;File"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  24 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetMenuBar</span><span class="Operator">(</span><span class="ID">menubar</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  25 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_MENU</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">101</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnQuit</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  26 </span>        <span class="ID">nb</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Notebook</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">NB_BOTTOM</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  27 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">sheet1</span> <span class="Operator">=</span> <span class="ID">MySheet</span><span class="Operator">(</span><span class="ID">nb</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  28 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">sheet2</span> <span class="Operator">=</span> <span class="ID">MySheet</span><span class="Operator">(</span><span class="ID">nb</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  29 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">sheet3</span> <span class="Operator">=</span> <span class="ID">MySheet</span><span class="Operator">(</span><span class="ID">nb</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  30 </span>        <span class="ID">nb</span><span class="Operator">.</span><span class="ID">AddPage</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">sheet1</span><span class="Operator">,</span> <span class="String">"Sheet1"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  31 </span>        <span class="ID">nb</span><span class="Operator">.</span><span class="ID">AddPage</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">sheet2</span><span class="Operator">,</span> <span class="String">"Sheet2"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  32 </span>        <span class="ID">nb</span><span class="Operator">.</span><span class="ID">AddPage</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">sheet3</span><span class="Operator">,</span> <span class="String">"Sheet3"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  33 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">sheet1</span><span class="Operator">.</span><span class="ID">SetFocus</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  34 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">StatusBar</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  35 </span></span>
<span class="line"><span class="LineNumber">  36 </span>    <span class="ResWord">def</span> <span class="ID">StatusBar</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  37 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">statusbar</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">CreateStatusBar</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  38 </span></span>
<span class="line"><span class="LineNumber">  39 </span>    <span class="ResWord">def</span> <span class="ID">OnQuit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  40 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Close</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  41 </span></span>
<span class="line"><span class="LineNumber">  42 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  43 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  44 </span>         <span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">Notebook</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'notebook.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  45 </span>         <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  46 </span>         <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  47 </span>         <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  48 </span></span>
<span class="line"><span class="LineNumber">  49 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  50 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-3174"></span><p class="line867"><img alt="notebook.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_047.png" title="notebook.png"> <span class="anchor" id="line-3175"></span><span class="anchor" id="line-3176"></span></p><p class="line867"><strong>Figure: notebook.py</strong> <span class="anchor" id="line-3177"></span><span class="anchor" id="line-3178"></span></p><p class="line867">
</p><h2 id="wx.lib_Classes">wx.lib Classes</h2>
<span class="anchor" id="line-3179"></span><p class="line874">Under lib directory we can find other widgets, improvements or extensions. Here we will show some more useful classes. <span class="anchor" id="line-3180"></span><span class="anchor" id="line-3181"></span></p><p class="line867">
</p><h3 id="Mouse_Gestures">Mouse Gestures</h3>
<span class="anchor" id="line-3182"></span><p class="line874">We can 
find mouse gestures in such successfull applications like Firefox or 
Opera. They really help users save their time while browsing on the 
Interent. Mouse gestures are created with <span class="anchor" id="line-3183"></span><span class="anchor" id="line-3184"></span></p><p class="line867"><tt>wx.lib.gestures.MouseGestures</tt> class in wxPython. <br>
 <br>
 <span class="anchor" id="line-3185"></span></p><div><table><tbody><tr>  <td colspan="2" style="text-align: center;"><p class="line891"><strong><tt>Possible&nbsp;methods</tt></strong> </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-3186"></span><p class="line891"><tt>AddGesture(string&nbsp;gesture,&nbsp;action)</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">registers a mouse gesture </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-3187"></span><p class="line891"><tt>RemoveGesture(string&nbsp;gesture)</tt> </p></td>
  <td><p class="line862">removes a mouse gesture </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-3188"></span><p class="line891"><tt>SetGesturePen(wx.Colour&nbsp;colour,&nbsp;integer&nbsp;width)</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">sets the colour and width of the line drawn to visually represent each gesture </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-3189"></span><p class="line891"><tt>SetGesturesVisible(boolean&nbsp;vis)</tt> </p></td>
  <td><p class="line862">sets wether a line is drawn to visually represent each gesture </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-3190"></span><p class="line891"><tt>SetWobbleTolerance(integer&nbsp;wobbletolerance)</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">sets the intensity to trigger a gesture </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-3191"></span><p class="line891"><tt>SetModifiers(list&nbsp;modifiers)</tt> </p></td>
  <td><p class="line862">takes a list of wx.Key constants (Control, Shift, and/or Alt) </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-3192"></span><p class="line891"><tt>SetMouseButton(integer&nbsp;flag)</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">takes the wx constant for the target mousebutton </p></td>
</tr>
</tbody></table></div><span class="anchor" id="line-3193"></span><span class="anchor" id="line-3194"></span><span class="anchor" id="line-3195"></span><span class="anchor" id="line-3196"></span><span class="anchor" id="line-3197"></span><p class="line874">Available gestures: <span class="anchor" id="line-3198"></span><span class="anchor" id="line-3199"></span></p><ul><li>L for left <span class="anchor" id="line-3200"></span></li><li>R for right <span class="anchor" id="line-3201"></span></li><li>U for up <span class="anchor" id="line-3202"></span></li><li>D for down <span class="anchor" id="line-3203"></span></li><li>7 for northwest <span class="anchor" id="line-3204"></span></li><li>9 for northeast <span class="anchor" id="line-3205"></span></li><li>1 for southwest <span class="anchor" id="line-3206"></span></li><li>3 for southeast <span class="anchor" id="line-3207"></span><span class="anchor" id="line-3208"></span></li></ul><p class="line874">If
 you wonder why these numbers were chosen, have a look at the numerical 
pad. Mouse gestures can be combined. This way 'RDLU' is a mouse gesture 
triggered, when we do a square with a mouse pointer. <span class="anchor" id="line-3209"></span><span class="anchor" id="line-3210"></span></p><p class="line874">Possible flags are: <span class="anchor" id="line-3211"></span><span class="anchor" id="line-3212"></span></p><ul><li>wx.MOUSE_BTN_LEFT <span class="anchor" id="line-3213"></span></li><li>wx.MOUSE_BTN_MIDDLE <span class="anchor" id="line-3214"></span></li><li>wx.MOUSE_BTN_RIGHT <span class="anchor" id="line-3215"></span><span class="anchor" id="line-3216"></span></li></ul><p class="line867"><span class="anchor" id="line-3217"></span><span class="anchor" id="line-3218"></span><span class="anchor" id="line-3219"></span><span class="anchor" id="line-3220"></span><span class="anchor" id="line-3221"></span><span class="anchor" id="line-3222"></span><span class="anchor" id="line-3223"></span><span class="anchor" id="line-3224"></span><span class="anchor" id="line-3225"></span><span class="anchor" id="line-3226"></span><span class="anchor" id="line-3227"></span><span class="anchor" id="line-3228"></span><span class="anchor" id="line-3229"></span><span class="anchor" id="line-3230"></span><span class="anchor" id="line-3231"></span><span class="anchor" id="line-3232"></span><span class="anchor" id="line-3233"></span><span class="anchor" id="line-3234"></span><span class="anchor" id="line-3235"></span><span class="anchor" id="line-3236"></span><span class="anchor" id="line-3237"></span><span class="anchor" id="line-3238"></span><span class="anchor" id="line-3239"></span><span class="anchor" id="line-3240"></span><span class="anchor" id="line-3241"></span><span class="anchor" id="line-3242"></span><span class="anchor" id="line-3243"></span><span class="anchor" id="line-3244"></span><span class="anchor" id="line-3245"></span><span class="anchor" id="line-3246"></span><span class="anchor" id="line-3247"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-74146b6cbc7dcf1f2affa4bd21413fe3f5760650\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-74146b6cbc7dcf1f2affa4bd21413fe3f5760650', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-74146b6cbc7dcf1f2affa4bd21413fe3f5760650" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># mousegestures.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span><span class="ResWord">import</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">lib</span><span class="Operator">.</span><span class="ID">gestures</span> <span class="ResWord">as</span> <span class="ID">gest</span></span>
<span class="line"><span class="LineNumber">   7 </span></span>
<span class="line"><span class="LineNumber">   8 </span><span class="ResWord">class</span> <span class="ID">MyMouseGestures</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span> <span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  10 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">600</span><span class="Operator">,</span> <span class="Number">500</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  11 </span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">panel</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">mg</span> <span class="Operator">=</span> <span class="ID">gest</span><span class="Operator">.</span><span class="ID">MouseGestures</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="ID">True</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MOUSE_BTN_LEFT</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">mg</span><span class="Operator">.</span><span class="ID">SetGesturePen</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Colour</span><span class="Operator">(</span><span class="Number">255</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Number">2</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">mg</span><span class="Operator">.</span><span class="ID">SetGesturesVisible</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span>        <span class="ID">mg</span><span class="Operator">.</span><span class="ID">AddGesture</span><span class="Operator">(</span><span class="String">'DR'</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnDownRight</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span></span>
<span class="line"><span class="LineNumber">  18 </span>    <span class="ResWord">def</span> <span class="ID">OnDownRight</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  19 </span>          <span class="ID">self</span><span class="Operator">.</span><span class="ID">Close</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  20 </span></span>
<span class="line"><span class="LineNumber">  21 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  22 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  23 </span>        <span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">MyMouseGestures</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">"mousegestures.py"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  24 </span>        <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  25 </span>        <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  26 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  27 </span></span>
<span class="line"><span class="LineNumber">  28 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  29 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-3248"></span><p class="line874">In
 our example, we have registered a mouse gesture for a panel. Mouse 
gesture is triggered, when a left button is pressed and we go down and 
right with a cursor. As in letter 'L'. Our mouse gesture will close the 
application. If we want to use mouse gestures, we have to create a <span class="anchor" id="line-3249"></span><span class="anchor" id="line-3250"></span></p><p class="line867"><tt>MouseGesture&nbsp;object</tt>.
 The first parameter is a window, where the mouse gesture is  
registered. Second parameter defines a way to register a gesture. True 
is for automatic, False for manual. Manual is not fully implemented and 
we are happy with the automatic way. Last parameter defines a mouse 
button, which will be pressed when triggering gestures. The button can 
be later changed with the <tt>SetMouseButton()</tt> method. <span class="anchor" id="line-3251"></span><span class="anchor" id="line-3252"></span></p><p class="line867"><span class="anchor" id="line-3253"></span><span class="anchor" id="line-3254"></span></p><pre>mg = gest.MouseGestures(panel, True, wx.MOUSE_BTN_LEFT)</pre><span class="anchor" id="line-3255"></span><p class="line874">Our gestures will be painted as red lines. They will be 2 pixels wide. <span class="anchor" id="line-3256"></span><span class="anchor" id="line-3257"></span></p><p class="line867"><span class="anchor" id="line-3258"></span><span class="anchor" id="line-3259"></span></p><pre>mg.SetGesturePen(wx.Colour(255, 0, 0), 2)</pre><span class="anchor" id="line-3260"></span><p class="line862">We set this gesture visible with the<tt>SetGesturesVisible()</tt> method. <span class="anchor" id="line-3261"></span><span class="anchor" id="line-3262"></span></p><p class="line867"><span class="anchor" id="line-3263"></span><span class="anchor" id="line-3264"></span></p><pre>mg.SetGesturesVisible(True)</pre><span class="anchor" id="line-3265"></span><p class="line862">We register a mouse gesture with the<tt>AddGesture()</tt> method. The first parameter is the gesture. Second parameter is the method triggered by the gesture. <span class="anchor" id="line-3266"></span><span class="anchor" id="line-3267"></span></p><p class="line867"><span class="anchor" id="line-3268"></span><span class="anchor" id="line-3269"></span></p><pre>mg.AddGesture('DR', self.OnDownRight)</pre><span class="anchor" id="line-3270"></span><p class="line867">
</p><h3 id="AnalogClockWindow">AnalogClockWindow</h3>
<span class="anchor" id="line-3271"></span><p class="line874">Simple analog clock. <span class="anchor" id="line-3272"></span><span class="anchor" id="line-3273"></span></p><p class="line867"><span class="anchor" id="line-3274"></span><span class="anchor" id="line-3275"></span><span class="anchor" id="line-3276"></span><span class="anchor" id="line-3277"></span><span class="anchor" id="line-3278"></span><span class="anchor" id="line-3279"></span><span class="anchor" id="line-3280"></span><span class="anchor" id="line-3281"></span><span class="anchor" id="line-3282"></span><span class="anchor" id="line-3283"></span><span class="anchor" id="line-3284"></span><span class="anchor" id="line-3285"></span><span class="anchor" id="line-3286"></span><span class="anchor" id="line-3287"></span><span class="anchor" id="line-3288"></span><span class="anchor" id="line-3289"></span><span class="anchor" id="line-3290"></span><span class="anchor" id="line-3291"></span><span class="anchor" id="line-3292"></span><span class="anchor" id="line-3293"></span><span class="anchor" id="line-3294"></span><span class="anchor" id="line-3295"></span><span class="anchor" id="line-3296"></span><span class="anchor" id="line-3297"></span><span class="anchor" id="line-3298"></span><span class="anchor" id="line-3299"></span><span class="anchor" id="line-3300"></span><span class="anchor" id="line-3301"></span><span class="anchor" id="line-3302"></span><span class="anchor" id="line-3303"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-3dbacfc0abb96d5bb4d3f9fb789ee7623b21098f\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-3dbacfc0abb96d5bb4d3f9fb789ee7623b21098f', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-3dbacfc0abb96d5bb4d3f9fb789ee7623b21098f" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># analogclock.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span><span class="ResWord">from</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">lib</span> <span class="ResWord">import</span> <span class="ID">analogclock</span> <span class="ResWord">as</span> <span class="ID">ac</span></span>
<span class="line"><span class="LineNumber">   7 </span></span>
<span class="line"><span class="LineNumber">   8 </span><span class="ResWord">class</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  10 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  11 </span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">clock</span> <span class="Operator">=</span> <span class="ID">ac</span><span class="Operator">.</span><span class="ID">AnalogClockWindow</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">clock</span><span class="Operator">.</span><span class="ID">SetBackgroundColour</span><span class="Operator">(</span><span class="String">'gray'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">clock</span><span class="Operator">.</span><span class="ID">SetHandColours</span><span class="Operator">(</span><span class="String">'black'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">clock</span><span class="Operator">.</span><span class="ID">SetTickColours</span><span class="Operator">(</span><span class="String">'WHITE'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span>        <span class="ID">clock</span><span class="Operator">.</span><span class="ID">SetTickSizes</span><span class="Operator">(</span><span class="ID">h</span><span class="Operator">=</span><span class="Number">5</span><span class="Operator">,</span> <span class="ID">m</span><span class="Operator">=</span><span class="Number">2</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="ID">clock</span><span class="Operator">.</span><span class="ID">SetTickStyles</span><span class="Operator">(</span><span class="ID">ac</span><span class="Operator">.</span><span class="ID">TICKS_ROMAN</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  18 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetSize</span><span class="Operator">(</span><span class="Operator">(</span><span class="Number">400</span><span class="Operator">,</span><span class="Number">350</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  19 </span></span>
<span class="line"><span class="LineNumber">  20 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  21 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  22 </span>        <span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'analogclock.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  23 </span>        <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  24 </span>        <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  25 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  26 </span></span>
<span class="line"><span class="LineNumber">  27 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  28 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-3304"></span><p class="line874">Various clock styles: <span class="anchor" id="line-3305"></span><span class="anchor" id="line-3306"></span></p><p class="line867"><tt>SetClockStyle()</tt> <span class="anchor" id="line-3307"></span><span class="anchor" id="line-3308"></span></p><ul><li>SHOW_QUARTERS_TICKS <span class="anchor" id="line-3309"></span></li><li>SHOW_HOURS_TICKS <span class="anchor" id="line-3310"></span></li><li>SHOW_MINUTES_TICKS <span class="anchor" id="line-3311"></span></li><li>SHOW_HOURS_HAND <span class="anchor" id="line-3312"></span></li><li>SHOW_MINUTES_HAND <span class="anchor" id="line-3313"></span></li><li>SHOW_SECONDS_HAND <span class="anchor" id="line-3314"></span></li><li>SHOW_SHADOWS <span class="anchor" id="line-3315"></span></li><li>ROTATE_TICKS <span class="anchor" id="line-3316"></span></li><li>OVERLAP_TICKS <span class="anchor" id="line-3317"></span><span class="anchor" id="line-3318"></span></li></ul><p class="line874">Various ticks styles: <span class="anchor" id="line-3319"></span><span class="anchor" id="line-3320"></span></p><p class="line867"><tt>SetTickStyles()</tt> <span class="anchor" id="line-3321"></span><span class="anchor" id="line-3322"></span></p><ul><li>TICKS_NONE <span class="anchor" id="line-3323"></span></li><li>TICKS_SQUARE <span class="anchor" id="line-3324"></span></li><li>TICKS_CIRCLE <span class="anchor" id="line-3325"></span></li><li>TICKS_POLY <span class="anchor" id="line-3326"></span></li><li>TICKS_DECIMAL <span class="anchor" id="line-3327"></span></li><li>TICKS_ROMAN <span class="anchor" id="line-3328"></span><span class="anchor" id="line-3329"></span></li></ul><p class="line867"><img alt="analogclock.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_015.png" title="analogclock.png"> <span class="anchor" id="line-3330"></span><span class="anchor" id="line-3331"></span></p><p class="line867"><strong>Figure: analogclock.py</strong> <span class="anchor" id="line-3332"></span><span class="anchor" id="line-3333"></span></p><p class="line867">
</p><h3 id="Bitmap_Text_Buttons">Bitmap Text Buttons</h3>
<span class="anchor" id="line-3334"></span><p class="line862">We cannot use wx.Button class if we want to display text buttons with images. For this task, we have a<tt>wx.GenBitmapTextButton</tt> class. <span class="anchor" id="line-3335"></span><span class="anchor" id="line-3336"></span></p><p class="line874">The constructor is: <span class="anchor" id="line-3337"></span><span class="anchor" id="line-3338"></span></p><p class="line867"><span class="anchor" id="line-3339"></span><span class="anchor" id="line-3340"></span><span class="anchor" id="line-3341"></span></p><pre>wx.GenBitmapTextButton(parent, ID=-1, bitmap=wx.NullBitmap, label='', pos = wx.DefaultPosition, size = wx.DefaultSize,
                 style = 0, validator = wx.DefaultValidator, name = 'genbutton')</pre><span class="anchor" id="line-3342"></span><p class="line874">This class is found under wx.lib.buttons. <span class="anchor" id="line-3343"></span><span class="anchor" id="line-3344"></span></p><p class="line874">In our example we show a possible use for this class. <span class="anchor" id="line-3345"></span><span class="anchor" id="line-3346"></span></p><p class="line867"><span class="anchor" id="line-3347"></span><span class="anchor" id="line-3348"></span><span class="anchor" id="line-3349"></span><span class="anchor" id="line-3350"></span><span class="anchor" id="line-3351"></span><span class="anchor" id="line-3352"></span><span class="anchor" id="line-3353"></span><span class="anchor" id="line-3354"></span><span class="anchor" id="line-3355"></span><span class="anchor" id="line-3356"></span><span class="anchor" id="line-3357"></span><span class="anchor" id="line-3358"></span><span class="anchor" id="line-3359"></span><span class="anchor" id="line-3360"></span><span class="anchor" id="line-3361"></span><span class="anchor" id="line-3362"></span><span class="anchor" id="line-3363"></span><span class="anchor" id="line-3364"></span><span class="anchor" id="line-3365"></span><span class="anchor" id="line-3366"></span><span class="anchor" id="line-3367"></span><span class="anchor" id="line-3368"></span><span class="anchor" id="line-3369"></span><span class="anchor" id="line-3370"></span><span class="anchor" id="line-3371"></span><span class="anchor" id="line-3372"></span><span class="anchor" id="line-3373"></span><span class="anchor" id="line-3374"></span><span class="anchor" id="line-3375"></span><span class="anchor" id="line-3376"></span><span class="anchor" id="line-3377"></span><span class="anchor" id="line-3378"></span><span class="anchor" id="line-3379"></span><span class="anchor" id="line-3380"></span><span class="anchor" id="line-3381"></span><span class="anchor" id="line-3382"></span><span class="anchor" id="line-3383"></span><span class="anchor" id="line-3384"></span><span class="anchor" id="line-3385"></span><span class="anchor" id="line-3386"></span><span class="anchor" id="line-3387"></span><span class="anchor" id="line-3388"></span><span class="anchor" id="line-3389"></span><span class="anchor" id="line-3390"></span><span class="anchor" id="line-3391"></span><span class="anchor" id="line-3392"></span><span class="anchor" id="line-3393"></span><span class="anchor" id="line-3394"></span><span class="anchor" id="line-3395"></span><span class="anchor" id="line-3396"></span><span class="anchor" id="line-3397"></span><span class="anchor" id="line-3398"></span><span class="anchor" id="line-3399"></span><span class="anchor" id="line-3400"></span><span class="anchor" id="line-3401"></span><span class="anchor" id="line-3402"></span><span class="anchor" id="line-3403"></span><span class="anchor" id="line-3404"></span><span class="anchor" id="line-3405"></span><span class="anchor" id="line-3406"></span><span class="anchor" id="line-3407"></span><span class="anchor" id="line-3408"></span><span class="anchor" id="line-3409"></span><span class="anchor" id="line-3410"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-5967f5054f6259b6d5b4ddb4e90e3b5c47de28e3\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-5967f5054f6259b6d5b4ddb4e90e3b5c47de28e3', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-5967f5054f6259b6d5b4ddb4e90e3b5c47de28e3" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># genbitmaptextbutton.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span><span class="ResWord">from</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">lib</span><span class="Operator">.</span><span class="ID">buttons</span> <span class="ResWord">import</span> <span class="ID">GenBitmapTextButton</span></span>
<span class="line"><span class="LineNumber">   7 </span></span>
<span class="line"><span class="LineNumber">   8 </span><span class="ResWord">class</span> <span class="ID">MyDialog</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Dialog</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  10 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Dialog</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">size</span> <span class="Operator">=</span> <span class="Operator">(</span><span class="Number">200</span><span class="Operator">,</span> <span class="Number">220</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  11 </span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">panel</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">email</span> <span class="Operator">=</span> <span class="ID">GenBitmapTextButton</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bitmap</span><span class="Operator">(</span><span class="String">'email.png'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="String">'Mail'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">25</span><span class="Operator">,</span> <span class="Number">20</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">150</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">email</span><span class="Operator">.</span><span class="ID">SetBezelWidth</span><span class="Operator">(</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">email</span><span class="Operator">.</span><span class="ID">SetBackgroundColour</span><span class="Operator">(</span><span class="String">'#c2e6f8'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span>        <span class="ID">calendar</span> <span class="Operator">=</span> <span class="ID">GenBitmapTextButton</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">2</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bitmap</span><span class="Operator">(</span><span class="String">'calendar.png'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="String">'Calendar'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">25</span><span class="Operator">,</span> <span class="Number">56</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">150</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="ID">calendar</span><span class="Operator">.</span><span class="ID">SetBezelWidth</span><span class="Operator">(</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  18 </span>        <span class="ID">calendar</span><span class="Operator">.</span><span class="ID">SetBackgroundColour</span><span class="Operator">(</span><span class="String">'#c2e6f8'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  19 </span>        <span class="ID">contacts</span> <span class="Operator">=</span> <span class="ID">GenBitmapTextButton</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">3</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bitmap</span><span class="Operator">(</span><span class="String">'contacts.png'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="String">'Contacts'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">25</span><span class="Operator">,</span> <span class="Number">92</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">150</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  20 </span>        <span class="ID">contacts</span><span class="Operator">.</span><span class="ID">SetBezelWidth</span><span class="Operator">(</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  21 </span>        <span class="ID">contacts</span><span class="Operator">.</span><span class="ID">SetBackgroundColour</span><span class="Operator">(</span><span class="String">'#c2e6f8'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  22 </span>        <span class="ID">tasks</span> <span class="Operator">=</span> <span class="ID">GenBitmapTextButton</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">4</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bitmap</span><span class="Operator">(</span><span class="String">'tasks.png'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="String">'Tasks'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">25</span><span class="Operator">,</span> <span class="Number">128</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">150</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  23 </span>        <span class="ID">tasks</span><span class="Operator">.</span><span class="ID">SetBezelWidth</span><span class="Operator">(</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  24 </span>        <span class="ID">tasks</span><span class="Operator">.</span><span class="ID">SetBackgroundColour</span><span class="Operator">(</span><span class="String">'#c2e6f8'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  25 </span>        <span class="ID">notes</span> <span class="Operator">=</span> <span class="ID">GenBitmapTextButton</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">5</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bitmap</span><span class="Operator">(</span><span class="String">'notes.png'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="String">'Notes'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">25</span><span class="Operator">,</span> <span class="Number">164</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">150</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  26 </span>        <span class="ID">notes</span><span class="Operator">.</span><span class="ID">SetBezelWidth</span><span class="Operator">(</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  27 </span>        <span class="ID">notes</span><span class="Operator">.</span><span class="ID">SetBackgroundColour</span><span class="Operator">(</span><span class="String">'#c2e6f8'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  28 </span></span>
<span class="line"><span class="LineNumber">  29 </span>        <span class="ID">email</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_ENTER_WINDOW</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnButtonEnter</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  30 </span>        <span class="ID">email</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_LEAVE_WINDOW</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnButtonLeave</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  31 </span>        <span class="ID">calendar</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_ENTER_WINDOW</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnButtonEnter</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  32 </span>        <span class="ID">calendar</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_LEAVE_WINDOW</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnButtonLeave</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  33 </span>        <span class="ID">contacts</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_ENTER_WINDOW</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnButtonEnter</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  34 </span>        <span class="ID">contacts</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_LEAVE_WINDOW</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnButtonLeave</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  35 </span>        <span class="ID">tasks</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_ENTER_WINDOW</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnButtonEnter</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  36 </span>        <span class="ID">tasks</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_LEAVE_WINDOW</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnButtonLeave</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  37 </span>        <span class="ID">notes</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_ENTER_WINDOW</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnButtonEnter</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  38 </span>        <span class="ID">notes</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_LEAVE_WINDOW</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnButtonLeave</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  39 </span></span>
<span class="line"><span class="LineNumber">  40 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  41 </span></span>
<span class="line"><span class="LineNumber">  42 </span>    <span class="ResWord">def</span> <span class="ID">OnButtonEnter</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  43 </span>        <span class="ID">obj</span> <span class="Operator">=</span>  <span class="ID">event</span><span class="Operator">.</span><span class="ID">GetEventObject</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  44 </span>        <span class="ID">obj</span><span class="Operator">.</span><span class="ID">SetBackgroundColour</span><span class="Operator">(</span><span class="String">'#ffdf85'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  45 </span>        <span class="ID">obj</span><span class="Operator">.</span><span class="ID">Refresh</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  46 </span></span>
<span class="line"><span class="LineNumber">  47 </span>    <span class="ResWord">def</span> <span class="ID">OnButtonLeave</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  48 </span>        <span class="ID">obj</span> <span class="Operator">=</span>  <span class="ID">event</span><span class="Operator">.</span><span class="ID">GetEventObject</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  49 </span>        <span class="ID">obj</span><span class="Operator">.</span><span class="ID">SetBackgroundColour</span><span class="Operator">(</span><span class="String">'#c2e6f8'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  50 </span>        <span class="ID">obj</span><span class="Operator">.</span><span class="ID">Refresh</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  51 </span></span>
<span class="line"><span class="LineNumber">  52 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  53 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  54 </span>        <span class="ID">dlg</span> <span class="Operator">=</span> <span class="ID">MyDialog</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'gentextbitmapbutton.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  55 </span>        <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">ShowModal</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  56 </span>        <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">Destroy</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  57 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  58 </span></span>
<span class="line"><span class="LineNumber">  59 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  60 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-3411"></span><p class="line867"><img alt="genbitmaptextbutton.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_037.png" title="genbitmaptextbutton.png"> <span class="anchor" id="line-3412"></span><span class="anchor" id="line-3413"></span></p><p class="line867"><strong>Figure: genbitmaptextbutton.py</strong> <span class="anchor" id="line-3414"></span><span class="anchor" id="line-3415"></span></p><p class="line867">
</p><h2 id="Advanced_Widgets">Advanced Widgets</h2>
<span class="anchor" id="line-3416"></span><p class="line874">In this 
section we will discuss some advanced widgets. They are found in lib 
subdirectory which is in wx directory. These widgets are written in 
python. They address needs not covered by the underlying C++ wx library.
 <span class="anchor" id="line-3417"></span><span class="anchor" id="line-3418"></span></p><p class="line867">
</p><h3 id="CalendarCtrl">CalendarCtrl</h3>
<span class="anchor" id="line-3419"></span><p class="line867"><a class="nonexistent" href="http://wiki.wxpython.org/CalendarCtrl">CalendarCtrl</a> is a handy widget for working with dates. <span class="anchor" id="line-3420"></span><span class="anchor" id="line-3421"></span></p><p class="line867"><span class="anchor" id="line-3422"></span><span class="anchor" id="line-3423"></span><span class="anchor" id="line-3424"></span><span class="anchor" id="line-3425"></span><span class="anchor" id="line-3426"></span><span class="anchor" id="line-3427"></span><span class="anchor" id="line-3428"></span><span class="anchor" id="line-3429"></span><span class="anchor" id="line-3430"></span><span class="anchor" id="line-3431"></span><span class="anchor" id="line-3432"></span><span class="anchor" id="line-3433"></span><span class="anchor" id="line-3434"></span><span class="anchor" id="line-3435"></span><span class="anchor" id="line-3436"></span><span class="anchor" id="line-3437"></span><span class="anchor" id="line-3438"></span><span class="anchor" id="line-3439"></span><span class="anchor" id="line-3440"></span><span class="anchor" id="line-3441"></span><span class="anchor" id="line-3442"></span><span class="anchor" id="line-3443"></span><span class="anchor" id="line-3444"></span><span class="anchor" id="line-3445"></span><span class="anchor" id="line-3446"></span><span class="anchor" id="line-3447"></span><span class="anchor" id="line-3448"></span><span class="anchor" id="line-3449"></span><span class="anchor" id="line-3450"></span><span class="anchor" id="line-3451"></span><span class="anchor" id="line-3452"></span><span class="anchor" id="line-3453"></span><span class="anchor" id="line-3454"></span><span class="anchor" id="line-3455"></span><span class="anchor" id="line-3456"></span><span class="anchor" id="line-3457"></span><span class="anchor" id="line-3458"></span><span class="anchor" id="line-3459"></span><span class="anchor" id="line-3460"></span><span class="anchor" id="line-3461"></span><span class="anchor" id="line-3462"></span><span class="anchor" id="line-3463"></span><span class="anchor" id="line-3464"></span><span class="anchor" id="line-3465"></span><span class="anchor" id="line-3466"></span><span class="anchor" id="line-3467"></span><span class="anchor" id="line-3468"></span><span class="anchor" id="line-3469"></span><span class="anchor" id="line-3470"></span><span class="anchor" id="line-3471"></span><span class="anchor" id="line-3472"></span><span class="anchor" id="line-3473"></span><span class="anchor" id="line-3474"></span><span class="anchor" id="line-3475"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-b29052d43c63557649f45c64f3d4b34bc66ca4d9\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-b29052d43c63557649f45c64f3d4b34bc66ca4d9', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-b29052d43c63557649f45c64f3d4b34bc66ca4d9" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># calendar.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span><span class="ResWord">import</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">calendar</span> <span class="ResWord">as</span> <span class="ID">cal</span></span>
<span class="line"><span class="LineNumber">   7 </span></span>
<span class="line"><span class="LineNumber">   8 </span><span class="ResWord">class</span> <span class="ID">Calendar</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Dialog</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  10 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Dialog</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  11 </span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">vbox</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BoxSizer</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">VERTICAL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">calend</span> <span class="Operator">=</span> <span class="ID">cal</span><span class="Operator">.</span><span class="ID">CalendarCtrl</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">DateTime_Now</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  15 </span>            <span class="ID">style</span> <span class="Operator">=</span> <span class="ID">cal</span><span class="Operator">.</span><span class="ID">CAL_SHOW_HOLIDAYS</span><span class="Operator">|</span><span class="ID">cal</span><span class="Operator">.</span><span class="ID">CAL_SEQUENTIAL_MONTH_SELECTION</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span>        <span class="ID">vbox</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">calend</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALL</span><span class="Operator">,</span> <span class="Number">20</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">cal</span><span class="Operator">.</span><span class="ID">EVT_CALENDAR</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnCalSelected</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="ID">calend</span><span class="Operator">.</span><span class="ID">GetId</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  18 </span></span>
<span class="line"><span class="LineNumber">  19 </span>        <span class="ID">vbox</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="Operator">(</span><span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="Number">20</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  20 </span></span>
<span class="line"><span class="LineNumber">  21 </span>        <span class="ID">hbox</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BoxSizer</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">HORIZONTAL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  22 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">text</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Date'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  23 </span>        <span class="ID">hbox</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">text</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  24 </span>        <span class="ID">vbox</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">hbox</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span>  <span class="ID">wx</span><span class="Operator">.</span><span class="ID">LEFT</span><span class="Operator">,</span> <span class="Number">8</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  25 </span></span>
<span class="line"><span class="LineNumber">  26 </span>        <span class="ID">hbox2</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BoxSizer</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">HORIZONTAL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  27 </span>        <span class="ID">btn</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Ok'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  28 </span>        <span class="ID">hbox2</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">btn</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  29 </span>        <span class="ID">vbox</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">hbox2</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_CENTER</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TOP</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BOTTOM</span><span class="Operator">,</span> <span class="Number">20</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  30 </span></span>
<span class="line"><span class="LineNumber">  31 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnQuit</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="ID">btn</span><span class="Operator">.</span><span class="ID">GetId</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  32 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_CLOSE</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnQuit</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  33 </span></span>
<span class="line"><span class="LineNumber">  34 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetSizerAndFit</span><span class="Operator">(</span><span class="ID">vbox</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  35 </span></span>
<span class="line"><span class="LineNumber">  36 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  37 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  38 </span></span>
<span class="line"><span class="LineNumber">  39 </span></span>
<span class="line"><span class="LineNumber">  40 </span>    <span class="ResWord">def</span> <span class="ID">OnCalSelected</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  41 </span>        <span class="ID">date</span> <span class="Operator">=</span> <span class="ID">event</span><span class="Operator">.</span><span class="ID">GetDate</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  42 </span>        <span class="ID">dt</span> <span class="Operator">=</span> <span class="ID">str</span><span class="Operator">(</span><span class="ID">date</span><span class="Operator">)</span><span class="Operator">.</span><span class="ID">split</span><span class="Operator">(</span><span class="String">' '</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  43 </span>        <span class="ID">s</span> <span class="Operator">=</span> <span class="String">' '</span><span class="Operator">.</span><span class="ID">join</span><span class="Operator">(</span><span class="ID">str</span><span class="Operator">(</span><span class="ID">s</span><span class="Operator">)</span> <span class="ResWord">for</span> <span class="ID">s</span> <span class="ResWord">in</span> <span class="ID">dt</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  44 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">text</span><span class="Operator">.</span><span class="ID">SetLabel</span><span class="Operator">(</span><span class="ID">s</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  45 </span></span>
<span class="line"><span class="LineNumber">  46 </span>    <span class="ResWord">def</span> <span class="ID">OnQuit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  47 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Destroy</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  48 </span></span>
<span class="line"><span class="LineNumber">  49 </span></span>
<span class="line"><span class="LineNumber">  50 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  51 </span><span class="ID">Calendar</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'calendar.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  52 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-3476"></span><p class="line874">Possible calendar styles: <span class="anchor" id="line-3477"></span><span class="anchor" id="line-3478"></span></p><p class="line867"><a href="http://wiki.wxpython.org/AnotherTutorial#head-85c7edde1489f8719d30c09af56c2effd00a77c6">Listed below.</a> <span class="anchor" id="line-3479"></span><span class="anchor" id="line-3480"></span></p><p class="line867"><img alt="calendar.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_003.png" title="calendar.png"> <span class="anchor" id="line-3481"></span><span class="anchor" id="line-3482"></span></p><p class="line867"><strong>Figure: calendar.py</strong> <span class="anchor" id="line-3483"></span><span class="anchor" id="line-3484"></span></p><p class="line867">
</p><h3 id="LEDNumberCtrl">LEDNumberCtrl</h3>
<span class="anchor" id="line-3485"></span><p class="line862">In the previous example we had an analog clock example.<tt>LEDNumberCtrl</tt> widget displays a digital clock. <span class="anchor" id="line-3486"></span><span class="anchor" id="line-3487"></span></p><p class="line874">In our example we show current local time in a simple wx.Frame. <span class="anchor" id="line-3488"></span><span class="anchor" id="line-3489"></span></p><p class="line867"><span class="anchor" id="line-3490"></span><span class="anchor" id="line-3491"></span><span class="anchor" id="line-3492"></span><span class="anchor" id="line-3493"></span><span class="anchor" id="line-3494"></span><span class="anchor" id="line-3495"></span><span class="anchor" id="line-3496"></span><span class="anchor" id="line-3497"></span><span class="anchor" id="line-3498"></span><span class="anchor" id="line-3499"></span><span class="anchor" id="line-3500"></span><span class="anchor" id="line-3501"></span><span class="anchor" id="line-3502"></span><span class="anchor" id="line-3503"></span><span class="anchor" id="line-3504"></span><span class="anchor" id="line-3505"></span><span class="anchor" id="line-3506"></span><span class="anchor" id="line-3507"></span><span class="anchor" id="line-3508"></span><span class="anchor" id="line-3509"></span><span class="anchor" id="line-3510"></span><span class="anchor" id="line-3511"></span><span class="anchor" id="line-3512"></span><span class="anchor" id="line-3513"></span><span class="anchor" id="line-3514"></span><span class="anchor" id="line-3515"></span><span class="anchor" id="line-3516"></span><span class="anchor" id="line-3517"></span><span class="anchor" id="line-3518"></span><span class="anchor" id="line-3519"></span><span class="anchor" id="line-3520"></span><span class="anchor" id="line-3521"></span><span class="anchor" id="line-3522"></span><span class="anchor" id="line-3523"></span><span class="anchor" id="line-3524"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-66fad352630f6907094c31af62a2e7a9481617ef\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-66fad352630f6907094c31af62a2e7a9481617ef', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-66fad352630f6907094c31af62a2e7a9481617ef" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># lednumber.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">time</span></span>
<span class="line"><span class="LineNumber">   6 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ResWord">import</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">gizmos</span> <span class="ResWord">as</span> <span class="ID">gizmos</span></span>
<span class="line"><span class="LineNumber">   8 </span></span>
<span class="line"><span class="LineNumber">   9 </span><span class="ResWord">class</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  10 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  11 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">DefaultPosition</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Size</span><span class="Operator">(</span><span class="Number">450</span><span class="Operator">,</span> <span class="Number">100</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  12 </span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">led</span> <span class="Operator">=</span> <span class="ID">gizmos</span><span class="Operator">.</span><span class="ID">LEDNumberCtrl</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">DefaultPosition</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">DefaultSize</span><span class="Operator">,</span> <span class="ID">gizmos</span><span class="Operator">.</span><span class="ID">LED_ALIGN_CENTER</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnTimer</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">timer</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Timer</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">timer</span><span class="Operator">.</span><span class="ID">Start</span><span class="Operator">(</span><span class="Number">1000</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_TIMER</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnTimer</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  18 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  19 </span></span>
<span class="line"><span class="LineNumber">  20 </span>    <span class="ResWord">def</span> <span class="ID">OnTimer</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  21 </span>        <span class="ID">t</span> <span class="Operator">=</span> <span class="ID">time</span><span class="Operator">.</span><span class="ID">localtime</span><span class="Operator">(</span><span class="ID">time</span><span class="Operator">.</span><span class="ID">time</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  22 </span>        <span class="ID">st</span> <span class="Operator">=</span> <span class="ID">time</span><span class="Operator">.</span><span class="ID">strftime</span><span class="Operator">(</span><span class="String">"%I:%M:%S"</span><span class="Operator">,</span> <span class="ID">t</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  23 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">led</span><span class="Operator">.</span><span class="ID">SetValue</span><span class="Operator">(</span><span class="ID">st</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  24 </span></span>
<span class="line"><span class="LineNumber">  25 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  26 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  27 </span>        <span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'lednumber.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  28 </span>        <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  29 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetTopWindow</span><span class="Operator">(</span><span class="ID">frame</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  30 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  31 </span></span>
<span class="line"><span class="LineNumber">  32 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  33 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-3525"></span><p class="line874">Possible flags: <span class="anchor" id="line-3526"></span><span class="anchor" id="line-3527"></span></p><ul><li>LED_ALIGN_LEFT <span class="anchor" id="line-3528"></span></li><li>LED_ALIGN_RIGHT <span class="anchor" id="line-3529"></span></li><li>LED_ALIGN_CENTER <span class="anchor" id="line-3530"></span></li><li>LED_ALIGN_MASK <span class="anchor" id="line-3531"></span></li><li>LED_DRAW_FADED <span class="anchor" id="line-3532"></span><span class="anchor" id="line-3533"></span></li></ul><p class="line862">Windows users, put<tt>wx.CallAfter()</tt> in your code: <span class="anchor" id="line-3534"></span><span class="anchor" id="line-3535"></span></p><p class="line867"><span class="anchor" id="line-3536"></span><span class="anchor" id="line-3537"></span><span class="anchor" id="line-3538"></span><span class="anchor" id="line-3539"></span></p><pre>self.led = gizmos.LEDNumberCtrl(self, -1, style=gizmos.LED_ALIGN_CENTER)
wx.CallAfter(self.OnTimer, None)
self.timer = wx.Timer(self, -1)</pre><span class="anchor" id="line-3540"></span><p class="line867"><img alt="lednumber.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_024.png" title="lednumber.png"> <span class="anchor" id="line-3541"></span><span class="anchor" id="line-3542"></span></p><p class="line867"><strong>Figure: lednumber.py</strong> <span class="anchor" id="line-3543"></span><span class="anchor" id="line-3544"></span></p><p class="line867">
</p><h2 id="Creating_a_taskbar_application">Creating a taskbar application</h2>
<span class="anchor" id="line-3545"></span><p class="line874">Some 
applications are placed on a taskbar. It is an area on a panel usually 
at the right bottom of the screen.  They are represented by a small 
icon. They are specialized programs designed to do some specific task.  
Common examples are a clock, sound mixer, language switcher. They are 
also called applets. In wxPython we have a <span class="anchor" id="line-3546"></span><span class="anchor" id="line-3547"></span></p><p class="line867"><tt>wx.TaskbarIcon</tt> class for creating such applets.  The constructor does not take any parameters. <span class="anchor" id="line-3548"></span><span class="anchor" id="line-3549"></span></p><p class="line867"><span class="anchor" id="line-3550"></span><span class="anchor" id="line-3551"></span></p><pre>wx.TaskbarIcon()</pre><span class="anchor" id="line-3552"></span><div><table><tbody><tr>  <td colspan="2" style="text-align: center;"><p class="line891"><strong>Available methods</strong> </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-3553"></span><p class="line891"><tt>Destroy()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">destroys a taskbaricon object </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-3554"></span><p class="line891"><tt>SetIcon(wx.Icon&nbsp;icon,&nbsp;string&nbsp;tooltip)</tt> </p></td>
  <td><p class="line862">sets an icon with optional tooltip </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-3555"></span><p class="line891"><tt>IsIconInstalled()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">checks if the icon is set </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-3556"></span><p class="line891"><tt>IsOk()</tt> </p></td>
  <td><p class="line862">checks if the object is created </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-3557"></span><p class="line891"><tt>RemoveIcon()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">removes the icon </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-3558"></span><p class="line891"><tt>PopupMenu(wx.Menu&nbsp;menu)</tt> </p></td>
  <td><p class="line862">pops up a menu </p></td>
</tr>
</tbody></table></div><span class="anchor" id="line-3559"></span><span class="anchor" id="line-3560"></span><span class="anchor" id="line-3561"></span><p class="line867"><span class="anchor" id="line-3562"></span><span class="anchor" id="line-3563"></span><span class="anchor" id="line-3564"></span><span class="anchor" id="line-3565"></span><span class="anchor" id="line-3566"></span><span class="anchor" id="line-3567"></span><span class="anchor" id="line-3568"></span><span class="anchor" id="line-3569"></span><span class="anchor" id="line-3570"></span><span class="anchor" id="line-3571"></span><span class="anchor" id="line-3572"></span><span class="anchor" id="line-3573"></span><span class="anchor" id="line-3574"></span><span class="anchor" id="line-3575"></span><span class="anchor" id="line-3576"></span><span class="anchor" id="line-3577"></span><span class="anchor" id="line-3578"></span><span class="anchor" id="line-3579"></span><span class="anchor" id="line-3580"></span><span class="anchor" id="line-3581"></span><span class="anchor" id="line-3582"></span><span class="anchor" id="line-3583"></span><span class="anchor" id="line-3584"></span><span class="anchor" id="line-3585"></span><span class="anchor" id="line-3586"></span><span class="anchor" id="line-3587"></span><span class="anchor" id="line-3588"></span><span class="anchor" id="line-3589"></span><span class="anchor" id="line-3590"></span><span class="anchor" id="line-3591"></span><span class="anchor" id="line-3592"></span><span class="anchor" id="line-3593"></span><span class="anchor" id="line-3594"></span><span class="anchor" id="line-3595"></span><span class="anchor" id="line-3596"></span><span class="anchor" id="line-3597"></span><span class="anchor" id="line-3598"></span><span class="anchor" id="line-3599"></span><span class="anchor" id="line-3600"></span><span class="anchor" id="line-3601"></span><span class="anchor" id="line-3602"></span><span class="anchor" id="line-3603"></span><span class="anchor" id="line-3604"></span><span class="anchor" id="line-3605"></span><span class="anchor" id="line-3606"></span><span class="anchor" id="line-3607"></span><span class="anchor" id="line-3608"></span><span class="anchor" id="line-3609"></span><span class="anchor" id="line-3610"></span><span class="anchor" id="line-3611"></span><span class="anchor" id="line-3612"></span><span class="anchor" id="line-3613"></span><span class="anchor" id="line-3614"></span><span class="anchor" id="line-3615"></span><span class="anchor" id="line-3616"></span><span class="anchor" id="line-3617"></span><span class="anchor" id="line-3618"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-4c80778cbab5473e5563f8b2697657dd9077150f\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-4c80778cbab5473e5563f8b2697657dd9077150f', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-4c80778cbab5473e5563f8b2697657dd9077150f" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># mytaskbaricon.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ResWord">class</span> <span class="ID">MyTaskBarIcon</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">TaskBarIcon</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   8 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TaskBarIcon</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  10 </span></span>
<span class="line"><span class="LineNumber">  11 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">frame</span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetIcon</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Icon</span><span class="Operator">(</span><span class="String">'web.png'</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BITMAP_TYPE_PNG</span><span class="Operator">)</span><span class="Operator">,</span> <span class="String">'mytaskbaricon.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_MENU</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnTaskBarActivate</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_MENU</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnTaskBarDeactivate</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">2</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_MENU</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnTaskBarClose</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">3</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span></span>
<span class="line"><span class="LineNumber">  17 </span>    <span class="ResWord">def</span> <span class="ID">CreatePopupMenu</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  18 </span>        <span class="ID">menu</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Menu</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  19 </span>        <span class="ID">menu</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Show'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  20 </span>        <span class="ID">menu</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="Number">2</span><span class="Operator">,</span> <span class="String">'Hide'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  21 </span>        <span class="ID">menu</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="Number">3</span><span class="Operator">,</span> <span class="String">'Close'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  22 </span>        <span class="ResWord">return</span> <span class="ID">menu</span></span>
<span class="line"><span class="LineNumber">  23 </span></span>
<span class="line"><span class="LineNumber">  24 </span>    <span class="ResWord">def</span> <span class="ID">OnTaskBarClose</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  25 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">frame</span><span class="Operator">.</span><span class="ID">Close</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  26 </span></span>
<span class="line"><span class="LineNumber">  27 </span>    <span class="ResWord">def</span> <span class="ID">OnTaskBarActivate</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  28 </span>        <span class="ResWord">if</span> <span class="ResWord">not</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">frame</span><span class="Operator">.</span><span class="ID">IsShown</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  29 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  30 </span></span>
<span class="line"><span class="LineNumber">  31 </span>    <span class="ResWord">def</span> <span class="ID">OnTaskBarDeactivate</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  32 </span>        <span class="ResWord">if</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">frame</span><span class="Operator">.</span><span class="ID">IsShown</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  33 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">frame</span><span class="Operator">.</span><span class="ID">Hide</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  34 </span></span>
<span class="line"><span class="LineNumber">  35 </span><span class="ResWord">class</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  36 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  37 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">290</span><span class="Operator">,</span> <span class="Number">280</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  38 </span></span>
<span class="line"><span class="LineNumber">  39 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tskic</span> <span class="Operator">=</span> <span class="ID">MyTaskBarIcon</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  40 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  41 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_CLOSE</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnClose</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  42 </span></span>
<span class="line"><span class="LineNumber">  43 </span>    <span class="ResWord">def</span> <span class="ID">OnClose</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  44 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tskic</span><span class="Operator">.</span><span class="ID">Destroy</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  45 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Destroy</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  46 </span></span>
<span class="line"><span class="LineNumber">  47 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  48 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  49 </span>        <span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'mytaskbaricon.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  50 </span>        <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  51 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetTopWindow</span><span class="Operator">(</span><span class="ID">frame</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  52 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  53 </span></span>
<span class="line"><span class="LineNumber">  54 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  55 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-3619"></span><p class="line867"><img alt="taskbaricon.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_039.png" title="taskbaricon.png"> <span class="anchor" id="line-3620"></span><span class="anchor" id="line-3621"></span></p><p class="line867"><strong>Figure: mytaskbaricon.py</strong> <span class="anchor" id="line-3622"></span><span class="anchor" id="line-3623"></span></p><p class="line867">
</p><h2 id="wx.TheClipboard">wx.TheClipboard</h2>
<span class="anchor" id="line-3624"></span><p class="line874">From wikipedia: <span class="anchor" id="line-3625"></span><span class="anchor" id="line-3626"></span></p><p class="line874">In
 computing, the clipboard is a portion of memory where information that 
has been copied or cut from a computer application is stored. This 
storage is meant as a short-term volatile place to keep information that
 will be used again shortly. <span class="anchor" id="line-3627"></span><span class="anchor" id="line-3628"></span></p><p class="line867"><tt>wx.TheClipboard</tt>
 is a class for manipulating clipboard in wxPython. Fist we must call 
the Open() method to get ownership of the clipboard. If successful, the 
method returns true. Then we put data on the clipboard with the <span class="anchor" id="line-3629"></span><span class="anchor" id="line-3630"></span></p><p class="line867"><tt>SetData()</tt> method.  This method accepts a simple data object. <span class="anchor" id="line-3631"></span><span class="anchor" id="line-3632"></span></p><p class="line874">We have three predefined simple data objects: <span class="anchor" id="line-3633"></span><span class="anchor" id="line-3634"></span></p><ul><li><p class="line891"><tt>wx.FileDataObject</tt> <span class="anchor" id="line-3635"></span></p></li><li><p class="line891"><tt>wx.TextDataObject</tt> <span class="anchor" id="line-3636"></span></p></li><li><p class="line891"><tt>wx.BitmapDataObject</tt> <span class="anchor" id="line-3637"></span><span class="anchor" id="line-3638"></span></p></li></ul><p class="line862">To retrieve data from Clipboard you call method<tt>GetData()</tt>. It accepts simple data object as well. In the end we close the clipboard with <tt>Close()&nbsp;</tt>method and relinquish ownership of it. <span class="anchor" id="line-3639"></span><span class="anchor" id="line-3640"></span></p><p class="line867"><tt>clipboard.py</tt> example shows a simple usage of the the clipboard in wxPython. <span class="anchor" id="line-3641"></span><span class="anchor" id="line-3642"></span></p><p class="line867"><span class="anchor" id="line-3643"></span><span class="anchor" id="line-3644"></span><span class="anchor" id="line-3645"></span><span class="anchor" id="line-3646"></span><span class="anchor" id="line-3647"></span><span class="anchor" id="line-3648"></span><span class="anchor" id="line-3649"></span><span class="anchor" id="line-3650"></span><span class="anchor" id="line-3651"></span><span class="anchor" id="line-3652"></span><span class="anchor" id="line-3653"></span><span class="anchor" id="line-3654"></span><span class="anchor" id="line-3655"></span><span class="anchor" id="line-3656"></span><span class="anchor" id="line-3657"></span><span class="anchor" id="line-3658"></span><span class="anchor" id="line-3659"></span><span class="anchor" id="line-3660"></span><span class="anchor" id="line-3661"></span><span class="anchor" id="line-3662"></span><span class="anchor" id="line-3663"></span><span class="anchor" id="line-3664"></span><span class="anchor" id="line-3665"></span><span class="anchor" id="line-3666"></span><span class="anchor" id="line-3667"></span><span class="anchor" id="line-3668"></span><span class="anchor" id="line-3669"></span><span class="anchor" id="line-3670"></span><span class="anchor" id="line-3671"></span><span class="anchor" id="line-3672"></span><span class="anchor" id="line-3673"></span><span class="anchor" id="line-3674"></span><span class="anchor" id="line-3675"></span><span class="anchor" id="line-3676"></span><span class="anchor" id="line-3677"></span><span class="anchor" id="line-3678"></span><span class="anchor" id="line-3679"></span><span class="anchor" id="line-3680"></span><span class="anchor" id="line-3681"></span><span class="anchor" id="line-3682"></span><span class="anchor" id="line-3683"></span><span class="anchor" id="line-3684"></span><span class="anchor" id="line-3685"></span><span class="anchor" id="line-3686"></span><span class="anchor" id="line-3687"></span><span class="anchor" id="line-3688"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-e8bfd23441fae70a02a5d13437019f6046a42bf0\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-e8bfd23441fae70a02a5d13437019f6046a42bf0', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-e8bfd23441fae70a02a5d13437019f6046a42bf0" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># clipboard.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ResWord">class</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   8 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">DefaultPosition</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Size</span><span class="Operator">(</span><span class="Number">320</span><span class="Operator">,</span> <span class="Number">300</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  10 </span></span>
<span class="line"><span class="LineNumber">  11 </span>        <span class="ID">panel1</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tc1</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TextCtrl</span><span class="Operator">(</span><span class="ID">panel1</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">50</span><span class="Operator">,</span><span class="Number">50</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">85</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tc2</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TextCtrl</span><span class="Operator">(</span><span class="ID">panel1</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">180</span><span class="Operator">,</span><span class="Number">50</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">85</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">panel1</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="String">'Copy'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">50</span><span class="Operator">,</span><span class="Number">200</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">panel1</span><span class="Operator">,</span> <span class="Number">2</span><span class="Operator">,</span> <span class="String">'Paste'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">180</span><span class="Operator">,</span><span class="Number">200</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnCopy</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnPaste</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">2</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  18 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  19 </span></span>
<span class="line"><span class="LineNumber">  20 </span>    <span class="ResWord">def</span> <span class="ID">OnCopy</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  21 </span>        <span class="ID">text</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tc1</span><span class="Operator">.</span><span class="ID">GetValue</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  22 </span>        <span class="ResWord">if</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TheClipboard</span><span class="Operator">.</span><span class="ID">Open</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  23 </span>            <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TheClipboard</span><span class="Operator">.</span><span class="ID">Clear</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  24 </span>            <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TheClipboard</span><span class="Operator">.</span><span class="ID">SetData</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">TextDataObject</span><span class="Operator">(</span><span class="ID">text</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  25 </span>            <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TheClipboard</span><span class="Operator">.</span><span class="ID">Close</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  26 </span></span>
<span class="line"><span class="LineNumber">  27 </span>    <span class="ResWord">def</span> <span class="ID">OnPaste</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  28 </span>        <span class="ResWord">if</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TheClipboard</span><span class="Operator">.</span><span class="ID">Open</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  29 </span>            <span class="ID">td</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TextDataObject</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  30 </span>            <span class="ID">success</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TheClipboard</span><span class="Operator">.</span><span class="ID">GetData</span><span class="Operator">(</span><span class="ID">td</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  31 </span>            <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TheClipboard</span><span class="Operator">.</span><span class="ID">Close</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  32 </span>            <span class="ResWord">if</span> <span class="ResWord">not</span> <span class="ID">success</span><span class="Operator">:</span> <span class="ResWord">return</span></span>
<span class="line"><span class="LineNumber">  33 </span>            <span class="ID">text</span> <span class="Operator">=</span> <span class="ID">td</span><span class="Operator">.</span><span class="ID">GetText</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  34 </span>            <span class="ResWord">if</span> <span class="ID">text</span><span class="Operator">:</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tc2</span><span class="Operator">.</span><span class="ID">SetValue</span><span class="Operator">(</span><span class="ID">text</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  35 </span></span>
<span class="line"><span class="LineNumber">  36 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  37 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  38 </span>        <span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'clipboard.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  39 </span>        <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  40 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetTopWindow</span><span class="Operator">(</span><span class="ID">frame</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  41 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  42 </span></span>
<span class="line"><span class="LineNumber">  43 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  44 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-3689"></span><p class="line862">We
 have two textcontrols and two buttons. We input some text into the 
first textcontrol and paste in the the second one with our two buttons. 
Notice how we retrieve data from the<tt>wxTextDataObject</tt>: <span class="anchor" id="line-3690"></span><span class="anchor" id="line-3691"></span></p><p class="line867"><span class="anchor" id="line-3692"></span><span class="anchor" id="line-3693"></span></p><pre>text = td.GetText()</pre><span class="anchor" id="line-3694"></span><p class="line867">
</p><h2 id="Drag_and_Drop">Drag and Drop</h2>
<span class="anchor" id="line-3695"></span><p class="line874">Wikipedia: <span class="anchor" id="line-3696"></span><span class="anchor" id="line-3697"></span></p><p class="line874">In
 computer graphical user interfaces, drag-and-drop is the action of (or 
support for the action of) clicking on a virtual object and dragging it 
to a different location or onto another virtual object. In general, it 
can be used to invoke many kinds of actions, or create various types of 
associations between two abstract objects. I think everyone is familiar 
with drag <span class="anchor" id="line-3698"></span><span class="anchor" id="line-3699"></span></p><p class="line867">&amp; drop. Here is an example in wxPython: <span class="anchor" id="line-3700"></span><span class="anchor" id="line-3701"></span></p><p class="line867"><span class="anchor" id="line-3702"></span><span class="anchor" id="line-3703"></span><span class="anchor" id="line-3704"></span><span class="anchor" id="line-3705"></span><span class="anchor" id="line-3706"></span><span class="anchor" id="line-3707"></span><span class="anchor" id="line-3708"></span><span class="anchor" id="line-3709"></span><span class="anchor" id="line-3710"></span><span class="anchor" id="line-3711"></span><span class="anchor" id="line-3712"></span><span class="anchor" id="line-3713"></span><span class="anchor" id="line-3714"></span><span class="anchor" id="line-3715"></span><span class="anchor" id="line-3716"></span><span class="anchor" id="line-3717"></span><span class="anchor" id="line-3718"></span><span class="anchor" id="line-3719"></span><span class="anchor" id="line-3720"></span><span class="anchor" id="line-3721"></span><span class="anchor" id="line-3722"></span><span class="anchor" id="line-3723"></span><span class="anchor" id="line-3724"></span><span class="anchor" id="line-3725"></span><span class="anchor" id="line-3726"></span><span class="anchor" id="line-3727"></span><span class="anchor" id="line-3728"></span><span class="anchor" id="line-3729"></span><span class="anchor" id="line-3730"></span><span class="anchor" id="line-3731"></span><span class="anchor" id="line-3732"></span><span class="anchor" id="line-3733"></span><span class="anchor" id="line-3734"></span><span class="anchor" id="line-3735"></span><span class="anchor" id="line-3736"></span><span class="anchor" id="line-3737"></span><span class="anchor" id="line-3738"></span><span class="anchor" id="line-3739"></span><span class="anchor" id="line-3740"></span><span class="anchor" id="line-3741"></span><span class="anchor" id="line-3742"></span><span class="anchor" id="line-3743"></span><span class="anchor" id="line-3744"></span><span class="anchor" id="line-3745"></span><span class="anchor" id="line-3746"></span><span class="anchor" id="line-3747"></span><span class="anchor" id="line-3748"></span><span class="anchor" id="line-3749"></span><span class="anchor" id="line-3750"></span><span class="anchor" id="line-3751"></span><span class="anchor" id="line-3752"></span><span class="anchor" id="line-3753"></span><span class="anchor" id="line-3754"></span><span class="anchor" id="line-3755"></span><span class="anchor" id="line-3756"></span><span class="anchor" id="line-3757"></span><span class="anchor" id="line-3758"></span><span class="anchor" id="line-3759"></span><span class="anchor" id="line-3760"></span><span class="anchor" id="line-3761"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-89f24e4dfd9508d2d7b3666c3a12b8d823c17c35\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-89f24e4dfd9508d2d7b3666c3a12b8d823c17c35', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-89f24e4dfd9508d2d7b3666c3a12b8d823c17c35" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># dragdrop.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">os</span></span>
<span class="line"><span class="LineNumber">   6 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   7 </span></span>
<span class="line"><span class="LineNumber">   8 </span><span class="ResWord">class</span> <span class="ID">MyTextDropTarget</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">TextDropTarget</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">object</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  10 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TextDropTarget</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  11 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">object</span> <span class="Operator">=</span> <span class="ID">object</span></span>
<span class="line"><span class="LineNumber">  12 </span></span>
<span class="line"><span class="LineNumber">  13 </span>    <span class="ResWord">def</span> <span class="ID">OnDropText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">x</span><span class="Operator">,</span> <span class="ID">y</span><span class="Operator">,</span> <span class="ID">data</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">object</span><span class="Operator">.</span><span class="ID">InsertStringItem</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">,</span> <span class="ID">data</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span></span>
<span class="line"><span class="LineNumber">  16 </span><span class="ResWord">class</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  17 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  18 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">DefaultPosition</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Size</span><span class="Operator">(</span><span class="Number">450</span><span class="Operator">,</span> <span class="Number">400</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  19 </span></span>
<span class="line"><span class="LineNumber">  20 </span>        <span class="ID">splitter1</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">SplitterWindow</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">SP_3D</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  21 </span>        <span class="ID">splitter2</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">SplitterWindow</span><span class="Operator">(</span><span class="ID">splitter1</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">SP_3D</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  22 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">dir</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">GenericDirCtrl</span><span class="Operator">(</span><span class="ID">splitter1</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">dir</span><span class="Operator">=</span><span class="String">'/home/'</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">DIRCTRL_DIR_ONLY</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  23 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">lc1</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ListCtrl</span><span class="Operator">(</span><span class="ID">splitter2</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">LC_LIST</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  24 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">lc2</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ListCtrl</span><span class="Operator">(</span><span class="ID">splitter2</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">LC_LIST</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  25 </span>        <span class="ID">dt</span> <span class="Operator">=</span> <span class="ID">MyTextDropTarget</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">lc2</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  26 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">lc2</span><span class="Operator">.</span><span class="ID">SetDropTarget</span><span class="Operator">(</span><span class="ID">dt</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  27 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_LIST_BEGIN_DRAG</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">lc1</span><span class="Operator">.</span><span class="ID">GetId</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnDragInit</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  28 </span>        <span class="ID">tree</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">dir</span><span class="Operator">.</span><span class="ID">GetTreeCtrl</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  29 </span>        <span class="ID">splitter2</span><span class="Operator">.</span><span class="ID">SplitHorizontally</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">lc1</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">lc2</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  30 </span>        <span class="ID">splitter1</span><span class="Operator">.</span><span class="ID">SplitVertically</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">dir</span><span class="Operator">,</span> <span class="ID">splitter2</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  31 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_TREE_SEL_CHANGED</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">tree</span><span class="Operator">.</span><span class="ID">GetId</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnSelect</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  32 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnSelect</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  33 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  34 </span></span>
<span class="line"><span class="LineNumber">  35 </span>    <span class="ResWord">def</span> <span class="ID">OnSelect</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  36 </span>        <span class="ID">list</span> <span class="Operator">=</span> <span class="ID">os</span><span class="Operator">.</span><span class="ID">listdir</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">dir</span><span class="Operator">.</span><span class="ID">GetPath</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  37 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">lc1</span><span class="Operator">.</span><span class="ID">ClearAll</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  38 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">lc2</span><span class="Operator">.</span><span class="ID">ClearAll</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  39 </span>        <span class="ResWord">for</span> <span class="ID">i</span> <span class="ResWord">in</span> <span class="ID">range</span><span class="Operator">(</span><span class="ID">len</span><span class="Operator">(</span><span class="ID">list</span><span class="Operator">)</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  40 </span>            <span class="ResWord">if</span> <span class="ID">list</span><span class="Operator">[</span><span class="ID">i</span><span class="Operator">]</span><span class="Operator">[</span><span class="Number">0</span><span class="Operator">]</span> <span class="Operator">!=</span> <span class="String">'.'</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  41 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">lc1</span><span class="Operator">.</span><span class="ID">InsertStringItem</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">,</span> <span class="ID">list</span><span class="Operator">[</span><span class="ID">i</span><span class="Operator">]</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  42 </span></span>
<span class="line"><span class="LineNumber">  43 </span>    <span class="ResWord">def</span> <span class="ID">OnDragInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  44 </span>        <span class="ID">text</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">lc1</span><span class="Operator">.</span><span class="ID">GetItemText</span><span class="Operator">(</span><span class="ID">event</span><span class="Operator">.</span><span class="ID">GetIndex</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  45 </span>        <span class="ID">tdo</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">PyTextDataObject</span><span class="Operator">(</span><span class="ID">text</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  46 </span>        <span class="ID">tds</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">DropSource</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">lc1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  47 </span>        <span class="ID">tds</span><span class="Operator">.</span><span class="ID">SetData</span><span class="Operator">(</span><span class="ID">tdo</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  48 </span>        <span class="ID">tds</span><span class="Operator">.</span><span class="ID">DoDragDrop</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  49 </span></span>
<span class="line"><span class="LineNumber">  50 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  51 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  52 </span>        <span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">"dragdrop.py"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  53 </span>        <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  54 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetTopWindow</span><span class="Operator">(</span><span class="ID">frame</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  55 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  56 </span></span>
<span class="line"><span class="LineNumber">  57 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  58 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-3762"></span><p class="line867"><img alt="dragdrop.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_022.png" title="dragdrop.png"> <span class="anchor" id="line-3763"></span><span class="anchor" id="line-3764"></span></p><p class="line867"><strong>Figure: dragdrop.py</strong> <span class="anchor" id="line-3765"></span><span class="anchor" id="line-3766"></span></p><p class="line874">One
 of the advantages of the GUI over the console is it's intuitiveness. 
You can learn a GUI program easier than a console application. You often
 do not need a manual. On the other hand, some graphical operations are 
too complex. For example, deleting a file by dragging it and droping it 
to the trash basket is very intuitive and easy to understand, but 
actually most people just press the delete key. (shift + delete) It is 
more effective. In our next example we explore a graphical operation, 
that is very handy. In most GUI text editors, you can open a file by 
simply dragging it from the file manager and dropping it on the editor. <span class="anchor" id="line-3767"></span><span class="anchor" id="line-3768"></span></p><p class="line867"><span class="anchor" id="line-3769"></span><span class="anchor" id="line-3770"></span><span class="anchor" id="line-3771"></span><span class="anchor" id="line-3772"></span><span class="anchor" id="line-3773"></span><span class="anchor" id="line-3774"></span><span class="anchor" id="line-3775"></span><span class="anchor" id="line-3776"></span><span class="anchor" id="line-3777"></span><span class="anchor" id="line-3778"></span><span class="anchor" id="line-3779"></span><span class="anchor" id="line-3780"></span><span class="anchor" id="line-3781"></span><span class="anchor" id="line-3782"></span><span class="anchor" id="line-3783"></span><span class="anchor" id="line-3784"></span><span class="anchor" id="line-3785"></span><span class="anchor" id="line-3786"></span><span class="anchor" id="line-3787"></span><span class="anchor" id="line-3788"></span><span class="anchor" id="line-3789"></span><span class="anchor" id="line-3790"></span><span class="anchor" id="line-3791"></span><span class="anchor" id="line-3792"></span><span class="anchor" id="line-3793"></span><span class="anchor" id="line-3794"></span><span class="anchor" id="line-3795"></span><span class="anchor" id="line-3796"></span><span class="anchor" id="line-3797"></span><span class="anchor" id="line-3798"></span><span class="anchor" id="line-3799"></span><span class="anchor" id="line-3800"></span><span class="anchor" id="line-3801"></span><span class="anchor" id="line-3802"></span><span class="anchor" id="line-3803"></span><span class="anchor" id="line-3804"></span><span class="anchor" id="line-3805"></span><span class="anchor" id="line-3806"></span><span class="anchor" id="line-3807"></span><span class="anchor" id="line-3808"></span><span class="anchor" id="line-3809"></span><span class="anchor" id="line-3810"></span><span class="anchor" id="line-3811"></span><span class="anchor" id="line-3812"></span><span class="anchor" id="line-3813"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-c4244b465f9a6d9e4535e682da5a11bcdf525f59\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-c4244b465f9a6d9e4535e682da5a11bcdf525f59', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-c4244b465f9a6d9e4535e682da5a11bcdf525f59" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># filedrop.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ResWord">class</span> <span class="ID">FileDrop</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">FileDropTarget</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   8 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">window</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">FileDropTarget</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  10 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">window</span> <span class="Operator">=</span> <span class="ID">window</span></span>
<span class="line"><span class="LineNumber">  11 </span></span>
<span class="line"><span class="LineNumber">  12 </span>    <span class="ResWord">def</span> <span class="ID">OnDropFiles</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">x</span><span class="Operator">,</span> <span class="ID">y</span><span class="Operator">,</span> <span class="ID">filenames</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  13 </span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ResWord">for</span> <span class="ID">name</span> <span class="ResWord">in</span> <span class="ID">filenames</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  15 </span>            <span class="ResWord">try</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  16 </span>                <span class="ID">file</span> <span class="Operator">=</span> <span class="ID">open</span><span class="Operator">(</span><span class="ID">name</span><span class="Operator">,</span> <span class="String">'r'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span>                <span class="ID">text</span> <span class="Operator">=</span> <span class="ID">file</span><span class="Operator">.</span><span class="ID">read</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  18 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">window</span><span class="Operator">.</span><span class="ID">WriteText</span><span class="Operator">(</span><span class="ID">text</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  19 </span>                <span class="ID">file</span><span class="Operator">.</span><span class="ID">close</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  20 </span>            <span class="ResWord">except</span> <span class="ID">IOError</span><span class="Operator">,</span> <span class="ID">error</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  21 </span>                <span class="ID">dlg</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MessageDialog</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="String">'Error opening file\n'</span> <span class="Operator">+</span> <span class="ID">str</span><span class="Operator">(</span><span class="ID">error</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  22 </span>                <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">ShowModal</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  23 </span>            <span class="ResWord">except</span> <span class="ID">UnicodeDecodeError</span><span class="Operator">,</span> <span class="ID">error</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  24 </span>                <span class="ID">dlg</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MessageDialog</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="String">'Cannot open non ascii files\n'</span> <span class="Operator">+</span> <span class="ID">str</span><span class="Operator">(</span><span class="ID">error</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  25 </span>                <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">ShowModal</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  26 </span></span>
<span class="line"><span class="LineNumber">  27 </span><span class="ResWord">class</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  28 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  29 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">DefaultPosition</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Size</span><span class="Operator">(</span><span class="Number">450</span><span class="Operator">,</span> <span class="Number">400</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  30 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">text</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TextCtrl</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">style</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TE_MULTILINE</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  31 </span>        <span class="ID">dt</span> <span class="Operator">=</span> <span class="ID">FileDrop</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">text</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  32 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">text</span><span class="Operator">.</span><span class="ID">SetDropTarget</span><span class="Operator">(</span><span class="ID">dt</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  33 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  34 </span></span>
<span class="line"><span class="LineNumber">  35 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  36 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  37 </span>        <span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  38 </span>        <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  39 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetTopWindow</span><span class="Operator">(</span><span class="ID">frame</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  40 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  41 </span></span>
<span class="line"><span class="LineNumber">  42 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  43 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-3814"></span><p class="line867">
</p><h2 id="Plotting">Plotting</h2>
<span class="anchor" id="line-3815"></span><p class="line874">wxPython comes with a simple plotting library. Features include zooming, legends and a grid. <span class="anchor" id="line-3816"></span><span class="anchor" id="line-3817"></span></p><p class="line874">Possible graphs: <span class="anchor" id="line-3818"></span><span class="anchor" id="line-3819"></span></p><ul><li>scatter <span class="anchor" id="line-3820"></span></li><li>line <span class="anchor" id="line-3821"></span></li><li>bar <span class="anchor" id="line-3822"></span><span class="anchor" id="line-3823"></span></li></ul><p class="line874">We must install the Numeric library. Other plotting libraries are <span class="anchor" id="line-3824"></span><span class="anchor" id="line-3825"></span></p><p class="line867"><tt>Gnuplot</tt> or <tt>MatPlotLib</tt>. These must be installed separately. <span class="anchor" id="line-3826"></span><span class="anchor" id="line-3827"></span></p><p class="line874">To create a graph, we follow these steps: <span class="anchor" id="line-3828"></span><span class="anchor" id="line-3829"></span></p><p class="line874">1) Define our data <span class="anchor" id="line-3830"></span><span class="anchor" id="line-3831"></span></p><p class="line874">we insert your data in a list of tuples. Each tuple will have two items. <span class="anchor" id="line-3832"></span><span class="anchor" id="line-3833"></span></p><p class="line874">data = [(x1, y1), (x2, y2), (x3, y3), (x4, y4), (x5, y5), (x6, y6)] <span class="anchor" id="line-3834"></span><span class="anchor" id="line-3835"></span></p><p class="line874">2) Create a plotting canvas we create an object of a <span class="anchor" id="line-3836"></span><span class="anchor" id="line-3837"></span></p><p class="line867"><tt>PlotCanvas</tt> as a child of a frame. <span class="anchor" id="line-3838"></span><span class="anchor" id="line-3839"></span></p><p class="line867"><span class="anchor" id="line-3840"></span><span class="anchor" id="line-3841"></span><span class="anchor" id="line-3842"></span></p><pre>   frame = wx.Frame(self, -1)
   client = wx.lib.plot.PlotCanvas(frame)</pre><span class="anchor" id="line-3843"></span><p class="line874">3) Create a graph There are two classes. <span class="anchor" id="line-3844"></span><span class="anchor" id="line-3845"></span></p><p class="line867"><tt>PolyLine</tt> and <tt>PolyMarker</tt>. <tt>PolyLine</tt> class defines line graphs. It's constructor is: <span class="anchor" id="line-3846"></span><span class="anchor" id="line-3847"></span></p><p class="line867"><span class="anchor" id="line-3848"></span><span class="anchor" id="line-3849"></span></p><pre>PolyLine(list data, wx.Colour colour, integer width, integer style, string legend)</pre><span class="anchor" id="line-3850"></span><p class="line862">data
 parameter is the data to be displayed. colour defines the colour of the
 line.  width is the width of the pen, used to draw the graph. possible 
style flags are wx.Pen styles<a href="http://wiki.wxpython.org/AnotherTutorial#head-942dbf77969587dcd8573cd7437116f26714a5b2">are listed below</a>. legend defines the line legend. <span class="anchor" id="line-3851"></span><span class="anchor" id="line-3852"></span></p><p class="line867"><tt>PolyMarker</tt> can be used to create scatter graphs and bar graphs as well. Constructor: <span class="anchor" id="line-3853"></span><span class="anchor" id="line-3854"></span></p><p class="line867"><span class="anchor" id="line-3855"></span><span class="anchor" id="line-3856"></span></p><pre>PolyMarker(list data, wx.Colour colour, integer size, wx.Colour fillcolour, integer fillstyle, string markershape, string legend)</pre><span class="anchor" id="line-3857"></span><p class="line874">fillstyle is also various wx.Pen styles. <span class="anchor" id="line-3858"></span><span class="anchor" id="line-3859"></span></p><p class="line874">Marker Shapes: <span class="anchor" id="line-3860"></span><span class="anchor" id="line-3861"></span></p><ul><li>circle <span class="anchor" id="line-3862"></span></li><li>dot <span class="anchor" id="line-3863"></span></li><li>square <span class="anchor" id="line-3864"></span></li><li>triangle <span class="anchor" id="line-3865"></span></li><li>triangle_down <span class="anchor" id="line-3866"></span></li><li>cross <span class="anchor" id="line-3867"></span></li><li>plus <span class="anchor" id="line-3868"></span><span class="anchor" id="line-3869"></span></li></ul><p class="line874">4) Create a graph container <span class="anchor" id="line-3870"></span><span class="anchor" id="line-3871"></span></p><p class="line874">Graph container is a container that holds a graph object and it's title and labels. <span class="anchor" id="line-3872"></span><span class="anchor" id="line-3873"></span></p><p class="line867"><span class="anchor" id="line-3874"></span><span class="anchor" id="line-3875"></span></p><pre>PlotGraphics(list objects, string title, string xLabel, string yLabel)</pre><span class="anchor" id="line-3876"></span><ul><li>objects is a list of one or more graph objects <span class="anchor" id="line-3877"></span></li><li>title - title shown at top of graph <span class="anchor" id="line-3878"></span></li><li>xLabel - label shown on x-axis <span class="anchor" id="line-3879"></span></li><li>yLabel - label shown on y-axis <span class="anchor" id="line-3880"></span><span class="anchor" id="line-3881"></span></li></ul><p class="line874">5) Draw a graph <span class="anchor" id="line-3882"></span><span class="anchor" id="line-3883"></span></p><p class="line874">finally we draw the graph. <span class="anchor" id="line-3884"></span><span class="anchor" id="line-3885"></span></p><p class="line867"><span class="anchor" id="line-3886"></span><span class="anchor" id="line-3887"></span></p><pre>client.Draw(gc,  xAxis=(0,15), yAxis=(0,15))</pre><span class="anchor" id="line-3888"></span><p class="line874">gc is a graph container object. xAxis and yAxis define the range of the axes <span class="anchor" id="line-3889"></span><span class="anchor" id="line-3890"></span></p><p class="line867"><span class="anchor" id="line-3891"></span><span class="anchor" id="line-3892"></span><span class="anchor" id="line-3893"></span><span class="anchor" id="line-3894"></span><span class="anchor" id="line-3895"></span><span class="anchor" id="line-3896"></span><span class="anchor" id="line-3897"></span><span class="anchor" id="line-3898"></span><span class="anchor" id="line-3899"></span><span class="anchor" id="line-3900"></span><span class="anchor" id="line-3901"></span><span class="anchor" id="line-3902"></span><span class="anchor" id="line-3903"></span><span class="anchor" id="line-3904"></span><span class="anchor" id="line-3905"></span><span class="anchor" id="line-3906"></span><span class="anchor" id="line-3907"></span><span class="anchor" id="line-3908"></span><span class="anchor" id="line-3909"></span><span class="anchor" id="line-3910"></span><span class="anchor" id="line-3911"></span><span class="anchor" id="line-3912"></span><span class="anchor" id="line-3913"></span><span class="anchor" id="line-3914"></span><span class="anchor" id="line-3915"></span><span class="anchor" id="line-3916"></span><span class="anchor" id="line-3917"></span><span class="anchor" id="line-3918"></span><span class="anchor" id="line-3919"></span><span class="anchor" id="line-3920"></span><span class="anchor" id="line-3921"></span><span class="anchor" id="line-3922"></span><span class="anchor" id="line-3923"></span><span class="anchor" id="line-3924"></span><span class="anchor" id="line-3925"></span><span class="anchor" id="line-3926"></span><span class="anchor" id="line-3927"></span><span class="anchor" id="line-3928"></span><span class="anchor" id="line-3929"></span><span class="anchor" id="line-3930"></span><span class="anchor" id="line-3931"></span><span class="anchor" id="line-3932"></span><span class="anchor" id="line-3933"></span><span class="anchor" id="line-3934"></span><span class="anchor" id="line-3935"></span><span class="anchor" id="line-3936"></span><span class="anchor" id="line-3937"></span><span class="anchor" id="line-3938"></span><span class="anchor" id="line-3939"></span><span class="anchor" id="line-3940"></span><span class="anchor" id="line-3941"></span><span class="anchor" id="line-3942"></span><span class="anchor" id="line-3943"></span><span class="anchor" id="line-3944"></span><span class="anchor" id="line-3945"></span><span class="anchor" id="line-3946"></span><span class="anchor" id="line-3947"></span><span class="anchor" id="line-3948"></span><span class="anchor" id="line-3949"></span><span class="anchor" id="line-3950"></span><span class="anchor" id="line-3951"></span><span class="anchor" id="line-3952"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-5222c1daa6a1e33fb968aa01389dd36261d75c58\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-5222c1daa6a1e33fb968aa01389dd36261d75c58', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-5222c1daa6a1e33fb968aa01389dd36261d75c58" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># plot.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span><span class="ResWord">import</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">lib</span><span class="Operator">.</span><span class="ID">plot</span> <span class="ResWord">as</span> <span class="ID">plot</span></span>
<span class="line"><span class="LineNumber">   7 </span></span>
<span class="line"><span class="LineNumber">   8 </span><span class="ResWord">class</span> <span class="ID">Plot</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Dialog</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>        <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  10 </span>                <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Dialog</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">180</span><span class="Operator">,</span> <span class="Number">280</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  11 </span></span>
<span class="line"><span class="LineNumber">  12 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">data</span> <span class="Operator">=</span> <span class="Operator">[</span><span class="Operator">(</span><span class="Number">1</span><span class="Operator">,</span><span class="Number">2</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">2</span><span class="Operator">,</span><span class="Number">3</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">3</span><span class="Operator">,</span><span class="Number">5</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">4</span><span class="Operator">,</span><span class="Number">6</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">5</span><span class="Operator">,</span><span class="Number">8</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">6</span><span class="Operator">,</span><span class="Number">8</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">10</span><span class="Operator">,</span><span class="Number">10</span><span class="Operator">)</span><span class="Operator">]</span></span>
<span class="line"><span class="LineNumber">  13 </span>                <span class="ID">btn1</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span>  <span class="Number">1</span><span class="Operator">,</span> <span class="String">'scatter'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">50</span><span class="Operator">,</span><span class="Number">50</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>                <span class="ID">btn2</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span>  <span class="Number">2</span><span class="Operator">,</span> <span class="String">'line'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">50</span><span class="Operator">,</span><span class="Number">90</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span>                <span class="ID">btn3</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span>  <span class="Number">3</span><span class="Operator">,</span> <span class="String">'bar'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">50</span><span class="Operator">,</span><span class="Number">130</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span>                <span class="ID">btn4</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span>  <span class="Number">4</span><span class="Operator">,</span> <span class="String">'quit'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">50</span><span class="Operator">,</span><span class="Number">170</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span>                <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnScatter</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  18 </span>                <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">2</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnLine</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  19 </span>                <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">3</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnBar</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  20 </span>                <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">4</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnQuit</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  21 </span>                <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_CLOSE</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnQuit</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  22 </span></span>
<span class="line"><span class="LineNumber">  23 </span>        <span class="ResWord">def</span> <span class="ID">OnScatter</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  24 </span>                <span class="ID">frm</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'scatter'</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">600</span><span class="Operator">,</span><span class="Number">450</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  25 </span>                <span class="ID">client</span> <span class="Operator">=</span> <span class="ID">plot</span><span class="Operator">.</span><span class="ID">PlotCanvas</span><span class="Operator">(</span><span class="ID">frm</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  26 </span>                <span class="ID">markers</span> <span class="Operator">=</span> <span class="ID">plot</span><span class="Operator">.</span><span class="ID">PolyMarker</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">data</span><span class="Operator">,</span> <span class="ID">legend</span><span class="Operator">=</span><span class="String">''</span><span class="Operator">,</span> <span class="ID">colour</span><span class="Operator">=</span><span class="String">'pink'</span><span class="Operator">,</span> <span class="ID">marker</span><span class="Operator">=</span><span class="String">'triangle_down'</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">=</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  27 </span>                <span class="ID">gc</span> <span class="Operator">=</span> <span class="ID">plot</span><span class="Operator">.</span><span class="ID">PlotGraphics</span><span class="Operator">(</span><span class="Operator">[</span><span class="ID">markers</span><span class="Operator">]</span><span class="Operator">,</span> <span class="String">'Scatter Graph'</span><span class="Operator">,</span> <span class="String">'X Axis'</span><span class="Operator">,</span> <span class="String">'Y Axis'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  28 </span>                <span class="ID">client</span><span class="Operator">.</span><span class="ID">Draw</span><span class="Operator">(</span><span class="ID">gc</span><span class="Operator">,</span> <span class="ID">xAxis</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">,</span><span class="Number">15</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">yAxis</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">,</span><span class="Number">15</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  29 </span>                <span class="ID">frm</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  30 </span></span>
<span class="line"><span class="LineNumber">  31 </span>        <span class="ResWord">def</span> <span class="ID">OnLine</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  32 </span>                <span class="ID">frm</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'line'</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">600</span><span class="Operator">,</span><span class="Number">450</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  33 </span>                <span class="ID">client</span> <span class="Operator">=</span> <span class="ID">plot</span><span class="Operator">.</span><span class="ID">PlotCanvas</span><span class="Operator">(</span><span class="ID">frm</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  34 </span>                <span class="ID">line</span> <span class="Operator">=</span> <span class="ID">plot</span><span class="Operator">.</span><span class="ID">PolyLine</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">data</span><span class="Operator">,</span> <span class="ID">legend</span><span class="Operator">=</span><span class="String">''</span><span class="Operator">,</span> <span class="ID">colour</span><span class="Operator">=</span><span class="String">'pink'</span><span class="Operator">,</span> <span class="ID">width</span><span class="Operator">=</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  35 </span>                <span class="ID">gc</span> <span class="Operator">=</span> <span class="ID">plot</span><span class="Operator">.</span><span class="ID">PlotGraphics</span><span class="Operator">(</span><span class="Operator">[</span><span class="ID">line</span><span class="Operator">]</span><span class="Operator">,</span> <span class="String">'Line Graph'</span><span class="Operator">,</span> <span class="String">'X Axis'</span><span class="Operator">,</span> <span class="String">'Y Axis'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  36 </span>                <span class="ID">client</span><span class="Operator">.</span><span class="ID">Draw</span><span class="Operator">(</span><span class="ID">gc</span><span class="Operator">,</span>  <span class="ID">xAxis</span><span class="Operator">=</span> <span class="Operator">(</span><span class="Number">0</span><span class="Operator">,</span><span class="Number">15</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">yAxis</span><span class="Operator">=</span> <span class="Operator">(</span><span class="Number">0</span><span class="Operator">,</span><span class="Number">15</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  37 </span>                <span class="ID">frm</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  38 </span></span>
<span class="line"><span class="LineNumber">  39 </span>        <span class="ResWord">def</span> <span class="ID">OnBar</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  40 </span>                <span class="ID">frm</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'bar'</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">600</span><span class="Operator">,</span><span class="Number">450</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  41 </span>                <span class="ID">client</span> <span class="Operator">=</span> <span class="ID">plot</span><span class="Operator">.</span><span class="ID">PlotCanvas</span><span class="Operator">(</span><span class="ID">frm</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  42 </span>                <span class="ID">bar1</span> <span class="Operator">=</span> <span class="ID">plot</span><span class="Operator">.</span><span class="ID">PolyLine</span><span class="Operator">(</span><span class="Operator">[</span><span class="Operator">(</span><span class="Number">1</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">1</span><span class="Operator">,</span><span class="Number">5</span><span class="Operator">)</span><span class="Operator">]</span><span class="Operator">,</span> <span class="ID">legend</span><span class="Operator">=</span><span class="String">''</span><span class="Operator">,</span> <span class="ID">colour</span><span class="Operator">=</span><span class="String">'gray'</span><span class="Operator">,</span> <span class="ID">width</span><span class="Operator">=</span><span class="Number">25</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  43 </span>                <span class="ID">bar2</span> <span class="Operator">=</span> <span class="ID">plot</span><span class="Operator">.</span><span class="ID">PolyLine</span><span class="Operator">(</span><span class="Operator">[</span><span class="Operator">(</span><span class="Number">3</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">3</span><span class="Operator">,</span><span class="Number">8</span><span class="Operator">)</span><span class="Operator">]</span><span class="Operator">,</span> <span class="ID">legend</span><span class="Operator">=</span><span class="String">''</span><span class="Operator">,</span> <span class="ID">colour</span><span class="Operator">=</span><span class="String">'gray'</span><span class="Operator">,</span> <span class="ID">width</span><span class="Operator">=</span><span class="Number">25</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  44 </span>                <span class="ID">bar3</span> <span class="Operator">=</span> <span class="ID">plot</span><span class="Operator">.</span><span class="ID">PolyLine</span><span class="Operator">(</span><span class="Operator">[</span><span class="Operator">(</span><span class="Number">5</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">5</span><span class="Operator">,</span><span class="Number">12</span><span class="Operator">)</span><span class="Operator">]</span><span class="Operator">,</span> <span class="ID">legend</span><span class="Operator">=</span><span class="String">''</span><span class="Operator">,</span> <span class="ID">colour</span><span class="Operator">=</span><span class="String">'gray'</span><span class="Operator">,</span> <span class="ID">width</span><span class="Operator">=</span><span class="Number">25</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  45 </span>                <span class="ID">bar4</span> <span class="Operator">=</span> <span class="ID">plot</span><span class="Operator">.</span><span class="ID">PolyLine</span><span class="Operator">(</span><span class="Operator">[</span><span class="Operator">(</span><span class="Number">6</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">6</span><span class="Operator">,</span><span class="Number">2</span><span class="Operator">)</span><span class="Operator">]</span><span class="Operator">,</span> <span class="ID">legend</span><span class="Operator">=</span><span class="String">''</span><span class="Operator">,</span> <span class="ID">colour</span><span class="Operator">=</span><span class="String">'gray'</span><span class="Operator">,</span> <span class="ID">width</span><span class="Operator">=</span><span class="Number">25</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  46 </span>                <span class="ID">gc</span> <span class="Operator">=</span> <span class="ID">plot</span><span class="Operator">.</span><span class="ID">PlotGraphics</span><span class="Operator">(</span><span class="Operator">[</span><span class="ID">bar1</span><span class="Operator">,</span> <span class="ID">bar2</span><span class="Operator">,</span> <span class="ID">bar3</span><span class="Operator">,</span> <span class="ID">bar4</span><span class="Operator">]</span><span class="Operator">,</span><span class="String">'Bar Graph'</span><span class="Operator">,</span> <span class="String">'X Axis'</span><span class="Operator">,</span> <span class="String">'Y Axis'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  47 </span>                <span class="ID">client</span><span class="Operator">.</span><span class="ID">Draw</span><span class="Operator">(</span><span class="ID">gc</span><span class="Operator">,</span> <span class="ID">xAxis</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">,</span><span class="Number">15</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">yAxis</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">,</span><span class="Number">15</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  48 </span>                <span class="ID">frm</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  49 </span></span>
<span class="line"><span class="LineNumber">  50 </span>        <span class="ResWord">def</span> <span class="ID">OnQuit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  51 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">Destroy</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  52 </span></span>
<span class="line"><span class="LineNumber">  53 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  54 </span>       <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  55 </span>                 <span class="ID">dlg</span> <span class="Operator">=</span> <span class="ID">Plot</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'plot.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  56 </span>                 <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  57 </span>                 <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  58 </span>                 <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  59 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  60 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-3953"></span><p class="line867"><img alt="scattergraph.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_016.png" title="scattergraph.png"> <img alt="linegraph.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_005.png" title="linegraph.png"> <img alt="bargraph.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_019.png" title="bargraph.png"> <span class="anchor" id="line-3954"></span><span class="anchor" id="line-3955"></span></p><p class="line867"><strong>Figures: scatter, line, bar graphs</strong> <span class="anchor" id="line-3956"></span><span class="anchor" id="line-3957"></span></p><p class="line867">
</p><h2 id="Configuring_application_settings">Configuring application settings</h2>
<span class="anchor" id="line-3958"></span><p class="line874">Many 
applications allow users to configure their settings. Users can toggle 
tooltips on and of, change fonts, default download paths etc. Mostly 
they have a menu option called preferences. Application settings are 
saved to the hard disk, so that users do not have to change the settings
 each time the application starts. <span class="anchor" id="line-3959"></span><span class="anchor" id="line-3960"></span></p><p class="line874">In wxPython we have wx.Config class to do our job. <span class="anchor" id="line-3961"></span><span class="anchor" id="line-3962"></span></p><p class="line874">On
 Linux, settings are stored in a simple hidden file. This file is 
located in the home user directory by default.  The location of the 
configuration file can be changed. The name of the file is specified in 
the constructor of the wx.Config class. <span class="anchor" id="line-3963"></span></p><div><table><tbody><tr>  <td colspan="2" style="text-align: center;"><p class="line891"><strong>Various wx.Config methods</strong> </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-3964"></span><p class="line891"><tt>string&nbsp;Read(string&nbsp;key,&nbsp;string&nbsp;defaultVal='')</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">return a string value of a key if it exists, defaultVal otherwise</p></td>
</tr>
<tr>  <td><span class="anchor" id="line-3965"></span><p class="line891"><tt>int&nbsp;ReadInt(string&nbsp;key,&nbsp;int&nbsp;defaultVal=0)</tt> </p></td>
  <td><p class="line862">return an integer value of the key if it exists, defaultVal otherwise</p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-3966"></span><p class="line891"><tt>float&nbsp;ReadFloat(string&nbsp;key,&nbsp;float&nbsp;defaultVal=0.0)</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">return a float value of a key if it exists, defaultVal otherwise</p></td>
</tr>
<tr>  <td><span class="anchor" id="line-3967"></span><p class="line891"><tt>bool&nbsp;ReadBool(string&nbsp;key,&nbsp;bool&nbsp;defaultVal=False)</tt> </p></td>
  <td><p class="line862">return a boolean value of a key if it exists, defaultVal otherwise</p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-3968"></span><p class="line891"><tt>bool&nbsp;Write(string&nbsp;key,&nbsp;string&nbsp;value)</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">write a string value, return True on success</p></td>
</tr>
<tr>  <td><span class="anchor" id="line-3969"></span><p class="line891"><tt>bool&nbsp;WriteInt(string&nbsp;key,&nbsp;int&nbsp;value)</tt> </p></td>
  <td><p class="line862">write an integer value, return True on success</p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-3970"></span><p class="line891"><tt>bool&nbsp;WriteFloat(string&nbsp;key,&nbsp;float&nbsp;value)</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">write a float value, return True on success</p></td>
</tr>
<tr>  <td><span class="anchor" id="line-3971"></span><p class="line891"><tt>bool&nbsp;WriteBool(string&nbsp;key,&nbsp;bool&nbsp;value)</tt> </p></td>
  <td><p class="line862">write a boolean value, return True on success</p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-3972"></span><p class="line891"><tt>bool&nbsp;Exists(string&nbsp;value)</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">return True if a key with a given name exists</p></td>
</tr>
</tbody></table></div><span class="anchor" id="line-3973"></span><span class="anchor" id="line-3974"></span><span class="anchor" id="line-3975"></span><span class="anchor" id="line-3976"></span><span class="anchor" id="line-3977"></span><p class="line874">In
 the following code example, we can cofigure the size of the window. If 
there is no configuration file, the height and the width of the window 
is set to the defaul 250 px value. We can set these values to a range 
from 200 - 500px. After we save our values and restart the application, 
the window size is set to our preffered values. <span class="anchor" id="line-3978"></span><span class="anchor" id="line-3979"></span></p><p class="line867"><span class="anchor" id="line-3980"></span><span class="anchor" id="line-3981"></span><span class="anchor" id="line-3982"></span><span class="anchor" id="line-3983"></span><span class="anchor" id="line-3984"></span><span class="anchor" id="line-3985"></span><span class="anchor" id="line-3986"></span><span class="anchor" id="line-3987"></span><span class="anchor" id="line-3988"></span><span class="anchor" id="line-3989"></span><span class="anchor" id="line-3990"></span><span class="anchor" id="line-3991"></span><span class="anchor" id="line-3992"></span><span class="anchor" id="line-3993"></span><span class="anchor" id="line-3994"></span><span class="anchor" id="line-3995"></span><span class="anchor" id="line-3996"></span><span class="anchor" id="line-3997"></span><span class="anchor" id="line-3998"></span><span class="anchor" id="line-3999"></span><span class="anchor" id="line-4000"></span><span class="anchor" id="line-4001"></span><span class="anchor" id="line-4002"></span><span class="anchor" id="line-4003"></span><span class="anchor" id="line-4004"></span><span class="anchor" id="line-4005"></span><span class="anchor" id="line-4006"></span><span class="anchor" id="line-4007"></span><span class="anchor" id="line-4008"></span><span class="anchor" id="line-4009"></span><span class="anchor" id="line-4010"></span><span class="anchor" id="line-4011"></span><span class="anchor" id="line-4012"></span><span class="anchor" id="line-4013"></span><span class="anchor" id="line-4014"></span><span class="anchor" id="line-4015"></span><span class="anchor" id="line-4016"></span><span class="anchor" id="line-4017"></span><span class="anchor" id="line-4018"></span><span class="anchor" id="line-4019"></span><span class="anchor" id="line-4020"></span><span class="anchor" id="line-4021"></span><span class="anchor" id="line-4022"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-7ba4f22958282d156551849dd41041bf3d19198e\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-7ba4f22958282d156551849dd41041bf3d19198e', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-7ba4f22958282d156551849dd41041bf3d19198e" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># myconfig.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ResWord">class</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   8 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">cfg</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Config</span><span class="Operator">(</span><span class="String">'myconfig'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  10 </span>        <span class="ResWord">if</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">cfg</span><span class="Operator">.</span><span class="ID">Exists</span><span class="Operator">(</span><span class="String">'width'</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  11 </span>            <span class="ID">w</span><span class="Operator">,</span> <span class="ID">h</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">cfg</span><span class="Operator">.</span><span class="ID">ReadInt</span><span class="Operator">(</span><span class="String">'width'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">cfg</span><span class="Operator">.</span><span class="ID">ReadInt</span><span class="Operator">(</span><span class="String">'height'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ResWord">else</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  13 </span>            <span class="Operator">(</span><span class="ID">w</span><span class="Operator">,</span> <span class="ID">h</span><span class="Operator">)</span> <span class="Operator">=</span> <span class="Operator">(</span><span class="Number">250</span><span class="Operator">,</span> <span class="Number">250</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">DefaultPosition</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Size</span><span class="Operator">(</span><span class="ID">w</span><span class="Operator">,</span> <span class="ID">h</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span></span>
<span class="line"><span class="LineNumber">  16 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Width:'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">20</span><span class="Operator">,</span> <span class="Number">20</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Height:'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">20</span><span class="Operator">,</span> <span class="Number">70</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  18 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">sc1</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">SpinCtrl</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">str</span><span class="Operator">(</span><span class="ID">w</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">80</span><span class="Operator">,</span> <span class="Number">15</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">60</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">min</span><span class="Operator">=</span><span class="Number">200</span><span class="Operator">,</span> <span class="ID">max</span><span class="Operator">=</span><span class="Number">500</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  19 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">sc2</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">SpinCtrl</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">str</span><span class="Operator">(</span><span class="ID">h</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">80</span><span class="Operator">,</span> <span class="Number">65</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">60</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">min</span><span class="Operator">=</span><span class="Number">200</span><span class="Operator">,</span> <span class="ID">max</span><span class="Operator">=</span><span class="Number">500</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  20 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="String">'Save'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">20</span><span class="Operator">,</span> <span class="Number">120</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  21 </span></span>
<span class="line"><span class="LineNumber">  22 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnSave</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  23 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">statusbar</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">CreateStatusBar</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  24 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  25 </span></span>
<span class="line"><span class="LineNumber">  26 </span>    <span class="ResWord">def</span> <span class="ID">OnSave</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  27 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">cfg</span><span class="Operator">.</span><span class="ID">WriteInt</span><span class="Operator">(</span><span class="String">"width"</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">sc1</span><span class="Operator">.</span><span class="ID">GetValue</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  28 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">cfg</span><span class="Operator">.</span><span class="ID">WriteInt</span><span class="Operator">(</span><span class="String">"height"</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">sc2</span><span class="Operator">.</span><span class="ID">GetValue</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  29 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">statusbar</span><span class="Operator">.</span><span class="ID">SetStatusText</span><span class="Operator">(</span><span class="String">'Configuration saved, %s '</span> <span class="Operator">%</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Now</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  30 </span></span>
<span class="line"><span class="LineNumber">  31 </span></span>
<span class="line"><span class="LineNumber">  32 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  33 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  34 </span>        <span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'myconfig.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  35 </span>        <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  36 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetTopWindow</span><span class="Operator">(</span><span class="ID">frame</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  37 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  38 </span></span>
<span class="line"><span class="LineNumber">  39 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  40 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-4023"></span><p class="line874">Here we have the contents of a configuration file to our code example . It consists of two key, value pairs. <span class="anchor" id="line-4024"></span><span class="anchor" id="line-4025"></span></p><p class="line867"><span class="anchor" id="line-4026"></span><span class="anchor" id="line-4027"></span><span class="anchor" id="line-4028"></span><span class="anchor" id="line-4029"></span></p><pre>$ cat .myconfig
height=220
width=340</pre><span class="anchor" id="line-4030"></span><p class="line867"><img alt="myconfig.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_050.png" title="myconfig.png"> <span class="anchor" id="line-4031"></span><span class="anchor" id="line-4032"></span></p><p class="line867"><strong>Figure: myconfig.py</strong> <span class="anchor" id="line-4033"></span><span class="anchor" id="line-4034"></span></p><p class="line867">
</p><h2 id="wxPython_functions">wxPython functions</h2>
<span class="anchor" id="line-4035"></span><p class="line874">wxPython 
provides several useful functions. We can implement them easily in our 
programs.  Technically, these functions are module functions. e.g 
defined in a module scope. They resemble what we know as static methods 
in C++ or Java. <span class="anchor" id="line-4036"></span><span class="anchor" id="line-4037"></span></p><p class="line867">
</p><h3 id="System_functions">System functions</h3>
<span class="anchor" id="line-4038"></span><div><table><tbody><tr>  <td colspan="2" style="text-align: center;"><p class="line891"><strong>System functions</strong> </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-4039"></span><p class="line891"><tt>wx.Bell()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">beep a sound </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-4040"></span><p class="line891"><tt>wx.GetDisplaySize()</tt> </p></td>
  <td><p class="line862">return the current display mode </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-4041"></span><p class="line891"><tt>wx.GetEmailAddress()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">return user's email address </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-4042"></span><p class="line891"><tt>wx.GetFullHostName()</tt> </p></td>
  <td><p class="line862">return full host name </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-4043"></span><p class="line891"><tt>wx.GetHomeDir()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">return the user's home direstory </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-4044"></span><p class="line891"><tt>wx.GetOsVersion()</tt> </p></td>
  <td><p class="line862">return Os version </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-4045"></span><p class="line891"><tt>wx.GetOsDescription()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">return a full Os description </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-4046"></span><p class="line891"><tt>wx.GetFreeMemory()</tt> </p></td>
  <td><p class="line862">not working </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-4047"></span><p class="line891"><tt>wx.GetMousePosition()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">return mouse position </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-4048"></span><p class="line891"><tt>wx.GetProcessId()</tt> </p></td>
  <td><p class="line862">return a process id of our application </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-4049"></span><p class="line891"><tt>wx.GetUserName()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">returns a user's name </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-4050"></span><p class="line891"><tt>wx.GetUTCTime()</tt> </p></td>
  <td><p class="line862">return number of seconds </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-4051"></span><p class="line891"><tt>wx.Now()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">return current timestamp </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-4052"></span><p class="line891"><tt>wx.Shell(string&nbsp;command)</tt> </p></td>
  <td><p class="line862">execute a command in a shell </p></td>
</tr>
</tbody></table></div><span class="anchor" id="line-4053"></span><span class="anchor" id="line-4054"></span><span class="anchor" id="line-4055"></span><p class="line867">
</p><h3 id="Dialog_functions">Dialog functions</h3>
<span class="anchor" id="line-4056"></span><p class="line874">These functions create dialogs. They do some common tasks. <span class="anchor" id="line-4057"></span></p><div><table><tbody><tr>  <td colspan="2" style="text-align: center;"><p class="line891"><strong>Dialog functions</strong> </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-4058"></span><p class="line891"><tt>wx.GetTextFromUser()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">get a text from user </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-4059"></span><p class="line891"><tt>wx.DirSelector()</tt> </p></td>
  <td><p class="line862">select a directory </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-4060"></span><p class="line891"><tt>wx.FileSelector()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">select a file </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-4061"></span><p class="line891"><tt>wx.GetNumberFromUser()</tt> </p></td>
  <td><p class="line862">get a long number from user </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-4062"></span><p class="line891"><tt>wx.GetSingleChoice()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">something </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-4063"></span><p class="line891"><tt>wx.GetSingleChoiceIndex()</tt> </p></td>
  <td><p class="line862">something </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-4064"></span><p class="line891"><tt>wx.GetSingleChoiceIndex()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">something </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-4065"></span><p class="line891"><tt>wx.LoadFileSelector()</tt> </p></td>
  <td><p class="line862">load a file </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-4066"></span><p class="line891"><tt>wx.MessageBox()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">show a message dialog </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-4067"></span><p class="line891"><tt>wx.SaveFileSelector()</tt> </p></td>
  <td><p class="line862">saves a file </p></td>
</tr>
</tbody></table></div><span class="anchor" id="line-4068"></span><span class="anchor" id="line-4069"></span><span class="anchor" id="line-4070"></span><span class="anchor" id="line-4071"></span><span class="anchor" id="line-4072"></span><p class="line867"><span class="anchor" id="line-4073"></span><span class="anchor" id="line-4074"></span><span class="anchor" id="line-4075"></span><span class="anchor" id="line-4076"></span><span class="anchor" id="line-4077"></span><span class="anchor" id="line-4078"></span><span class="anchor" id="line-4079"></span><span class="anchor" id="line-4080"></span><span class="anchor" id="line-4081"></span><span class="anchor" id="line-4082"></span><span class="anchor" id="line-4083"></span><span class="anchor" id="line-4084"></span><span class="anchor" id="line-4085"></span><span class="anchor" id="line-4086"></span><span class="anchor" id="line-4087"></span><span class="anchor" id="line-4088"></span><span class="anchor" id="line-4089"></span><span class="anchor" id="line-4090"></span><span class="anchor" id="line-4091"></span></p><pre>string wx.GetTextFromUser(string message, string caption='', string default_value='', wx.Window parent=None)
string wx.DirSelector(string message=wx.DirSelectorPromptStr, string defaultPath='', style=wx.DD_DEFAULT_STYLE,
                      wx.Point pos=wx.DefaultPosition, wx.Window parent=None)
string wx.FileSelector(string message=wx.FileSelectorPromptStr, string default_path='', string default_filename='',
                       string default_extension='', string wildcard=wx.FileSelectorDefaultWildcardStr,
                       integer flags=0, wx.Window parent=None, integer x=-1, integer y=-1)
long wx.GetNumberFromUser(string message, string prompt, string caption, long value, long min=0, long max=100,
                          wx.Window parent=None, wx.Point pos=wx.DefaultPosition)
string wx.GetSingleChoice(string message, string caption, integer choices, string choices_array,
                          wx.Window parent=None, integer x=-1, integer y=-1, bool centre=True, integer width=150,
                          integer height=200)
integer wx.GetSingleChoiceIndex(string message, string caption, integer choices, string choices_array,
                                wx.Window parent=None, integer x=-1, integer y=-1, bool centre=True,
                                integer width=150, integer height=200)
string wx.LoadFileSelector(string what, string extension, string default_name='', wx.Window parent=None)
integer wx.MessageBox(string message, string caption='', style=wx.OK | wx.CENTRE, wx.Window parent=None,
                      integer x=-1, integer y=-1)
string wx.SaveFileSelector(string what, string extension, string default_name='', wx.Window parent=None)</pre><span class="anchor" id="line-4092"></span><p class="line867">
</p><h3 id="Other_functions">Other functions</h3>
<span class="anchor" id="line-4093"></span><p class="line874">Here is a list of various other functions <span class="anchor" id="line-4094"></span></p><div><table><tbody><tr>  <td colspan="2" style="text-align: center;"><p class="line891"><strong>Other functions</strong> </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-4095"></span><p class="line891"><tt>wx.Exit()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">exit application </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-4096"></span><p class="line891"><tt>bool&nbsp;wx.Yield()</tt> </p></td>
  <td><p class="line862">yield to other applications or messages </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-4097"></span><p class="line891"><tt>bool&nbsp;wx.YieldIfNeeded()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">something </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-4098"></span><p class="line891"><tt>bool&nbsp;SafeYield(wx.Window&nbsp;window=None,&nbsp;bool&nbsp;onlyIfNeeded=False)</tt> </p></td>
  <td><p class="line862">something </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-4099"></span><p class="line891"><tt>wx.WakeUpIdle()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">empty the message queue </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-4100"></span><p class="line891"><tt>wx.PostEvent(wx.EvtHandler&nbsp;dest,&nbsp;wx.Event&nbsp;event)</tt> </p></td>
  <td><p class="line891"><tt>wx.EventHandler</tt> to be processed later </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-4101"></span><p class="line891"><tt>PyApp&nbsp;wx.GetApp()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">return a reference to the current wx.App object </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-4102"></span><p class="line891"><tt>wx.SetDefaultPyEncoding(string&nbsp;encoding)</tt> </p></td>
  <td><p class="line862">set the current encoding for working with wx.String </p></td>
</tr>
<tr>  <td style="background-color: rgb(208, 208, 208);"><span class="anchor" id="line-4103"></span><p class="line891"><tt>string&nbsp;wx.GetDefaultPyEncoding()</tt> </p></td>
  <td style="background-color: rgb(208, 208, 208);"><p class="line862">get the current encoding for working with wx.String </p></td>
</tr>
</tbody></table></div><span class="anchor" id="line-4104"></span><span class="anchor" id="line-4105"></span><span class="anchor" id="line-4106"></span><span class="anchor" id="line-4107"></span><span class="anchor" id="line-4108"></span><p class="line867">
</p><h2 id="Using_xml_resource_files">Using xml resource files</h2>
<span class="anchor" id="line-4109"></span><p class="line874">The idea 
behind xml resources is to separate the interface from the code of an 
application. Several GUI builders use this concept for creating 
interfaces. For example the famous Glade. <span class="anchor" id="line-4110"></span><span class="anchor" id="line-4111"></span></p><p class="line874">In
 our example we create a simple frame window with one button. We load 
resources from a file, load a panel and bind an event to a button. <span class="anchor" id="line-4112"></span><span class="anchor" id="line-4113"></span></p><p class="line867"><span class="anchor" id="line-4114"></span><span class="anchor" id="line-4115"></span><span class="anchor" id="line-4116"></span><span class="anchor" id="line-4117"></span><span class="anchor" id="line-4118"></span><span class="anchor" id="line-4119"></span><span class="anchor" id="line-4120"></span><span class="anchor" id="line-4121"></span><span class="anchor" id="line-4122"></span><span class="anchor" id="line-4123"></span><span class="anchor" id="line-4124"></span><span class="anchor" id="line-4125"></span><span class="anchor" id="line-4126"></span><span class="anchor" id="line-4127"></span><span class="anchor" id="line-4128"></span><span class="anchor" id="line-4129"></span><span class="anchor" id="line-4130"></span><span class="anchor" id="line-4131"></span><span class="anchor" id="line-4132"></span><span class="anchor" id="line-4133"></span><span class="anchor" id="line-4134"></span><span class="anchor" id="line-4135"></span><span class="anchor" id="line-4136"></span><span class="anchor" id="line-4137"></span><span class="anchor" id="line-4138"></span><span class="anchor" id="line-4139"></span><span class="anchor" id="line-4140"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-60ccd09a6422732529b69e7f8d445a88c4dd3e6d\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-60ccd09a6422732529b69e7f8d445a88c4dd3e6d', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-60ccd09a6422732529b69e7f8d445a88c4dd3e6d" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># xml.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span>  <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span><span class="ResWord">import</span>  <span class="ID">wx</span><span class="Operator">.</span><span class="ID">xrc</span>  <span class="ResWord">as</span>  <span class="ID">xrc</span></span>
<span class="line"><span class="LineNumber">   7 </span></span>
<span class="line"><span class="LineNumber">   8 </span><span class="ResWord">class</span> <span class="ID">Xml</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  10 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  11 </span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">res</span> <span class="Operator">=</span> <span class="ID">xrc</span><span class="Operator">.</span><span class="ID">XmlResource</span><span class="Operator">(</span><span class="String">'resource.xrc'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">res</span><span class="Operator">.</span><span class="ID">LoadPanel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="String">'MyPanel'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnClose</span><span class="Operator">,</span>  <span class="ID">id</span><span class="Operator">=</span><span class="ID">xrc</span><span class="Operator">.</span><span class="ID">XRCID</span><span class="Operator">(</span><span class="String">'CloseButton'</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Center</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  18 </span></span>
<span class="line"><span class="LineNumber">  19 </span></span>
<span class="line"><span class="LineNumber">  20 </span>    <span class="ResWord">def</span> <span class="ID">OnClose</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  21 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Close</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  22 </span></span>
<span class="line"><span class="LineNumber">  23 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  24 </span><span class="ID">Xml</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'xml.py'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  25 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-4141"></span><p class="line862">This
 is resource file resource.xrc It is a xml file, where we define our 
widgets and their patterns. In this file, we use tags 
like&lt;object&gt;&lt;/object&gt;, &lt;item&gt;&lt;/item&gt; etc. <span class="anchor" id="line-4142"></span><span class="anchor" id="line-4143"></span></p><p class="line867"><span class="anchor" id="line-4144"></span><span class="anchor" id="line-4145"></span><span class="anchor" id="line-4146"></span><span class="anchor" id="line-4147"></span><span class="anchor" id="line-4148"></span><span class="anchor" id="line-4149"></span><span class="anchor" id="line-4150"></span><span class="anchor" id="line-4151"></span><span class="anchor" id="line-4152"></span><span class="anchor" id="line-4153"></span></p><pre>&lt;?xml version="1.0" ?&gt;
&lt;resource&gt;
  &lt;object class="wxPanel" name="MyPanel"&gt;
   &lt;object class="wxButton" name="CloseButton"&gt;
    &lt;label&gt;Close&lt;/label&gt;
    &lt;pos&gt;150,100&lt;/pos&gt;
   &lt;/object&gt;
  &lt;/object&gt;
&lt;/resource&gt;</pre><span class="anchor" id="line-4154"></span><p class="line874">We use these two calls for working with widgets: <span class="anchor" id="line-4155"></span><span class="anchor" id="line-4156"></span></p><ul><li>XRCID(resource_name) - gives us the id of a button or menu item <span class="anchor" id="line-4157"></span></li><li>XRCCTRL(resource_name) - gives us the handlers of our widgets defined in resource file <span class="anchor" id="line-4158"></span><span class="anchor" id="line-4159"></span></li></ul><p class="line867">
</p><h2 id="Skeletons">Skeletons</h2>
<span class="anchor" id="line-4160"></span><p class="line874">In this 
section, we will create some application skeletons. Our scripts will 
work out the interface but will not implement the functionality. The 
goal is to show, how several well known GUI interfaces could be done in 
wxPython. Most manuals, tutorials and books show only the basic usage of
 a widget. When I was a beginner, I always wondered how this or this 
could be done. And I think, many newbies think the same. <span class="anchor" id="line-4161"></span><span class="anchor" id="line-4162"></span></p><p class="line867">
</p><h3 id="File_Hunter">File Hunter</h3>
<span class="anchor" id="line-4163"></span><p class="line874">File 
Hunter is a skeleton of a file manager. It copies the lookout of the 
Krusader, the best file manager available on Unix systems. <span class="anchor" id="line-4164"></span><span class="anchor" id="line-4165"></span></p><p class="line867"><span class="anchor" id="line-4166"></span><span class="anchor" id="line-4167"></span><span class="anchor" id="line-4168"></span><span class="anchor" id="line-4169"></span><span class="anchor" id="line-4170"></span><span class="anchor" id="line-4171"></span><span class="anchor" id="line-4172"></span><span class="anchor" id="line-4173"></span><span class="anchor" id="line-4174"></span><span class="anchor" id="line-4175"></span><span class="anchor" id="line-4176"></span><span class="anchor" id="line-4177"></span><span class="anchor" id="line-4178"></span><span class="anchor" id="line-4179"></span><span class="anchor" id="line-4180"></span><span class="anchor" id="line-4181"></span><span class="anchor" id="line-4182"></span><span class="anchor" id="line-4183"></span><span class="anchor" id="line-4184"></span><span class="anchor" id="line-4185"></span><span class="anchor" id="line-4186"></span><span class="anchor" id="line-4187"></span><span class="anchor" id="line-4188"></span><span class="anchor" id="line-4189"></span><span class="anchor" id="line-4190"></span><span class="anchor" id="line-4191"></span><span class="anchor" id="line-4192"></span><span class="anchor" id="line-4193"></span><span class="anchor" id="line-4194"></span><span class="anchor" id="line-4195"></span><span class="anchor" id="line-4196"></span><span class="anchor" id="line-4197"></span><span class="anchor" id="line-4198"></span><span class="anchor" id="line-4199"></span><span class="anchor" id="line-4200"></span><span class="anchor" id="line-4201"></span><span class="anchor" id="line-4202"></span><span class="anchor" id="line-4203"></span><span class="anchor" id="line-4204"></span><span class="anchor" id="line-4205"></span><span class="anchor" id="line-4206"></span><span class="anchor" id="line-4207"></span><span class="anchor" id="line-4208"></span><span class="anchor" id="line-4209"></span><span class="anchor" id="line-4210"></span><span class="anchor" id="line-4211"></span><span class="anchor" id="line-4212"></span><span class="anchor" id="line-4213"></span><span class="anchor" id="line-4214"></span><span class="anchor" id="line-4215"></span><span class="anchor" id="line-4216"></span><span class="anchor" id="line-4217"></span><span class="anchor" id="line-4218"></span><span class="anchor" id="line-4219"></span><span class="anchor" id="line-4220"></span><span class="anchor" id="line-4221"></span><span class="anchor" id="line-4222"></span><span class="anchor" id="line-4223"></span><span class="anchor" id="line-4224"></span><span class="anchor" id="line-4225"></span><span class="anchor" id="line-4226"></span><span class="anchor" id="line-4227"></span><span class="anchor" id="line-4228"></span><span class="anchor" id="line-4229"></span><span class="anchor" id="line-4230"></span><span class="anchor" id="line-4231"></span><span class="anchor" id="line-4232"></span><span class="anchor" id="line-4233"></span><span class="anchor" id="line-4234"></span><span class="anchor" id="line-4235"></span><span class="anchor" id="line-4236"></span><span class="anchor" id="line-4237"></span><span class="anchor" id="line-4238"></span><span class="anchor" id="line-4239"></span><span class="anchor" id="line-4240"></span><span class="anchor" id="line-4241"></span><span class="anchor" id="line-4242"></span><span class="anchor" id="line-4243"></span><span class="anchor" id="line-4244"></span><span class="anchor" id="line-4245"></span><span class="anchor" id="line-4246"></span><span class="anchor" id="line-4247"></span><span class="anchor" id="line-4248"></span><span class="anchor" id="line-4249"></span><span class="anchor" id="line-4250"></span><span class="anchor" id="line-4251"></span><span class="anchor" id="line-4252"></span><span class="anchor" id="line-4253"></span><span class="anchor" id="line-4254"></span><span class="anchor" id="line-4255"></span><span class="anchor" id="line-4256"></span><span class="anchor" id="line-4257"></span><span class="anchor" id="line-4258"></span><span class="anchor" id="line-4259"></span><span class="anchor" id="line-4260"></span><span class="anchor" id="line-4261"></span><span class="anchor" id="line-4262"></span><span class="anchor" id="line-4263"></span><span class="anchor" id="line-4264"></span><span class="anchor" id="line-4265"></span><span class="anchor" id="line-4266"></span><span class="anchor" id="line-4267"></span><span class="anchor" id="line-4268"></span><span class="anchor" id="line-4269"></span><span class="anchor" id="line-4270"></span><span class="anchor" id="line-4271"></span><span class="anchor" id="line-4272"></span><span class="anchor" id="line-4273"></span><span class="anchor" id="line-4274"></span><span class="anchor" id="line-4275"></span><span class="anchor" id="line-4276"></span><span class="anchor" id="line-4277"></span><span class="anchor" id="line-4278"></span><span class="anchor" id="line-4279"></span><span class="anchor" id="line-4280"></span><span class="anchor" id="line-4281"></span><span class="anchor" id="line-4282"></span><span class="anchor" id="line-4283"></span><span class="anchor" id="line-4284"></span><span class="anchor" id="line-4285"></span><span class="anchor" id="line-4286"></span><span class="anchor" id="line-4287"></span><span class="anchor" id="line-4288"></span><span class="anchor" id="line-4289"></span><span class="anchor" id="line-4290"></span><span class="anchor" id="line-4291"></span><span class="anchor" id="line-4292"></span><span class="anchor" id="line-4293"></span><span class="anchor" id="line-4294"></span><span class="anchor" id="line-4295"></span><span class="anchor" id="line-4296"></span><span class="anchor" id="line-4297"></span><span class="anchor" id="line-4298"></span><span class="anchor" id="line-4299"></span><span class="anchor" id="line-4300"></span><span class="anchor" id="line-4301"></span><span class="anchor" id="line-4302"></span><span class="anchor" id="line-4303"></span><span class="anchor" id="line-4304"></span><span class="anchor" id="line-4305"></span><span class="anchor" id="line-4306"></span><span class="anchor" id="line-4307"></span><span class="anchor" id="line-4308"></span><span class="anchor" id="line-4309"></span><span class="anchor" id="line-4310"></span><span class="anchor" id="line-4311"></span><span class="anchor" id="line-4312"></span><span class="anchor" id="line-4313"></span><span class="anchor" id="line-4314"></span><span class="anchor" id="line-4315"></span><span class="anchor" id="line-4316"></span><span class="anchor" id="line-4317"></span><span class="anchor" id="line-4318"></span><span class="anchor" id="line-4319"></span><span class="anchor" id="line-4320"></span><span class="anchor" id="line-4321"></span><span class="anchor" id="line-4322"></span><span class="anchor" id="line-4323"></span><span class="anchor" id="line-4324"></span><span class="anchor" id="line-4325"></span><span class="anchor" id="line-4326"></span><span class="anchor" id="line-4327"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-bf2bf89b8fa0e934833a6a85a62dc5db46d4408e\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-bf2bf89b8fa0e934833a6a85a62dc5db46d4408e', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-bf2bf89b8fa0e934833a6a85a62dc5db46d4408e" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="ResWord">import</span> <span class="ID">os</span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">time</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span></span>
<span class="line"><span class="LineNumber">   8 </span><span class="ID">ID_BUTTON</span><span class="Operator">=</span><span class="Number">100</span></span>
<span class="line"><span class="LineNumber">   9 </span><span class="ID">ID_EXIT</span><span class="Operator">=</span><span class="Number">200</span></span>
<span class="line"><span class="LineNumber">  10 </span><span class="ID">ID_SPLITTER</span><span class="Operator">=</span><span class="Number">300</span></span>
<span class="line"><span class="LineNumber">  11 </span></span>
<span class="line"><span class="LineNumber">  12 </span><span class="ResWord">class</span> <span class="ID">MyListCtrl</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">ListCtrl</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  13 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ListCtrl</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">LC_REPORT</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span></span>
<span class="line"><span class="LineNumber">  16 </span>        <span class="ID">files</span> <span class="Operator">=</span> <span class="ID">os</span><span class="Operator">.</span><span class="ID">listdir</span><span class="Operator">(</span><span class="String">'.'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="ID">images</span> <span class="Operator">=</span> <span class="Operator">[</span><span class="String">'images/empty.png'</span><span class="Operator">,</span> <span class="String">'images/folder.png'</span><span class="Operator">,</span> <span class="String">'images/source_py.png'</span><span class="Operator">,</span> <span class="String">'images/image.png'</span><span class="Operator">,</span> <span class="String">'images/pdf.png'</span><span class="Operator">,</span> <span class="String">'images/up16.png'</span><span class="Operator">]</span></span>
<span class="line"><span class="LineNumber">  18 </span></span>
<span class="line"><span class="LineNumber">  19 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">InsertColumn</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">,</span> <span class="String">'Name'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  20 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">InsertColumn</span><span class="Operator">(</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Ext'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  21 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">InsertColumn</span><span class="Operator">(</span><span class="Number">2</span><span class="Operator">,</span> <span class="String">'Size'</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">LIST_FORMAT_RIGHT</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  22 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">InsertColumn</span><span class="Operator">(</span><span class="Number">3</span><span class="Operator">,</span> <span class="String">'Modified'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  23 </span></span>
<span class="line"><span class="LineNumber">  24 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetColumnWidth</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">,</span> <span class="Number">220</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  25 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetColumnWidth</span><span class="Operator">(</span><span class="Number">1</span><span class="Operator">,</span> <span class="Number">70</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  26 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetColumnWidth</span><span class="Operator">(</span><span class="Number">2</span><span class="Operator">,</span> <span class="Number">100</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  27 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetColumnWidth</span><span class="Operator">(</span><span class="Number">3</span><span class="Operator">,</span> <span class="Number">420</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  28 </span></span>
<span class="line"><span class="LineNumber">  29 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">il</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ImageList</span><span class="Operator">(</span><span class="Number">16</span><span class="Operator">,</span> <span class="Number">16</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  30 </span>        <span class="ResWord">for</span> <span class="ID">i</span> <span class="ResWord">in</span> <span class="ID">images</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  31 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">il</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bitmap</span><span class="Operator">(</span><span class="ID">i</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  32 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetImageList</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">il</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">IMAGE_LIST_SMALL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  33 </span></span>
<span class="line"><span class="LineNumber">  34 </span>        <span class="ID">j</span> <span class="Operator">=</span> <span class="Number">1</span></span>
<span class="line"><span class="LineNumber">  35 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">InsertStringItem</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">,</span> <span class="String">'..'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  36 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetItemImage</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">,</span> <span class="Number">5</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  37 </span></span>
<span class="line"><span class="LineNumber">  38 </span>        <span class="ResWord">for</span> <span class="ID">i</span> <span class="ResWord">in</span> <span class="ID">files</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  39 </span>            <span class="Operator">(</span><span class="ID">name</span><span class="Operator">,</span> <span class="ID">ext</span><span class="Operator">)</span> <span class="Operator">=</span> <span class="ID">os</span><span class="Operator">.</span><span class="ID">path</span><span class="Operator">.</span><span class="ID">splitext</span><span class="Operator">(</span><span class="ID">i</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  40 </span>            <span class="ID">ex</span> <span class="Operator">=</span> <span class="ID">ext</span><span class="Operator">[</span><span class="Number">1</span><span class="Operator">:</span><span class="Operator">]</span></span>
<span class="line"><span class="LineNumber">  41 </span>            <span class="ID">size</span> <span class="Operator">=</span> <span class="ID">os</span><span class="Operator">.</span><span class="ID">path</span><span class="Operator">.</span><span class="ID">getsize</span><span class="Operator">(</span><span class="ID">i</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  42 </span>            <span class="ID">sec</span> <span class="Operator">=</span> <span class="ID">os</span><span class="Operator">.</span><span class="ID">path</span><span class="Operator">.</span><span class="ID">getmtime</span><span class="Operator">(</span><span class="ID">i</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  43 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">InsertStringItem</span><span class="Operator">(</span><span class="ID">j</span><span class="Operator">,</span> <span class="ID">name</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  44 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetStringItem</span><span class="Operator">(</span><span class="ID">j</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">ex</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  45 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetStringItem</span><span class="Operator">(</span><span class="ID">j</span><span class="Operator">,</span> <span class="Number">2</span><span class="Operator">,</span> <span class="ID">str</span><span class="Operator">(</span><span class="ID">size</span><span class="Operator">)</span> <span class="Operator">+</span> <span class="String">' B'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  46 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetStringItem</span><span class="Operator">(</span><span class="ID">j</span><span class="Operator">,</span> <span class="Number">3</span><span class="Operator">,</span> <span class="ID">time</span><span class="Operator">.</span><span class="ID">strftime</span><span class="Operator">(</span><span class="String">'%Y-%m-%d %H:%M'</span><span class="Operator">,</span> <span class="ID">time</span><span class="Operator">.</span><span class="ID">localtime</span><span class="Operator">(</span><span class="ID">sec</span><span class="Operator">)</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  47 </span></span>
<span class="line"><span class="LineNumber">  48 </span>            <span class="ResWord">if</span> <span class="ID">os</span><span class="Operator">.</span><span class="ID">path</span><span class="Operator">.</span><span class="ID">isdir</span><span class="Operator">(</span><span class="ID">i</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  49 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetItemImage</span><span class="Operator">(</span><span class="ID">j</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  50 </span>            <span class="ResWord">elif</span> <span class="ID">ex</span> <span class="Operator">==</span> <span class="String">'py'</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  51 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetItemImage</span><span class="Operator">(</span><span class="ID">j</span><span class="Operator">,</span> <span class="Number">2</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  52 </span>            <span class="ResWord">elif</span> <span class="ID">ex</span> <span class="Operator">==</span> <span class="String">'jpg'</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  53 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetItemImage</span><span class="Operator">(</span><span class="ID">j</span><span class="Operator">,</span> <span class="Number">3</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  54 </span>            <span class="ResWord">elif</span> <span class="ID">ex</span> <span class="Operator">==</span> <span class="String">'pdf'</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  55 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetItemImage</span><span class="Operator">(</span><span class="ID">j</span><span class="Operator">,</span> <span class="Number">4</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  56 </span>            <span class="ResWord">else</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  57 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetItemImage</span><span class="Operator">(</span><span class="ID">j</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  58 </span></span>
<span class="line"><span class="LineNumber">  59 </span>            <span class="ResWord">if</span> <span class="Operator">(</span><span class="ID">j</span> <span class="Operator">%</span> <span class="Number">2</span><span class="Operator">)</span> <span class="Operator">==</span> <span class="Number">0</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  60 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetItemBackgroundColour</span><span class="Operator">(</span><span class="ID">j</span><span class="Operator">,</span> <span class="String">'#e6f1f5'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  61 </span>            <span class="ID">j</span> <span class="Operator">+=</span> <span class="Number">1</span></span>
<span class="line"><span class="LineNumber">  62 </span></span>
<span class="line"><span class="LineNumber">  63 </span><span class="ResWord">class</span> <span class="ID">FileHunter</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  64 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  65 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  66 </span></span>
<span class="line"><span class="LineNumber">  67 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">splitter</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">SplitterWindow</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">ID_SPLITTER</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">SP_BORDER</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  68 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">splitter</span><span class="Operator">.</span><span class="ID">SetMinimumPaneSize</span><span class="Operator">(</span><span class="Number">50</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  69 </span></span>
<span class="line"><span class="LineNumber">  70 </span>        <span class="ID">p1</span> <span class="Operator">=</span> <span class="ID">MyListCtrl</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">splitter</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  71 </span>        <span class="ID">p2</span> <span class="Operator">=</span> <span class="ID">MyListCtrl</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">splitter</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  72 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">splitter</span><span class="Operator">.</span><span class="ID">SplitVertically</span><span class="Operator">(</span><span class="ID">p1</span><span class="Operator">,</span> <span class="ID">p2</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  73 </span></span>
<span class="line"><span class="LineNumber">  74 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_SIZE</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnSize</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  75 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_SPLITTER_DCLICK</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnDoubleClick</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="ID">ID_SPLITTER</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  76 </span></span>
<span class="line"><span class="LineNumber">  77 </span>        <span class="ID">filemenu</span><span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Menu</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  78 </span>        <span class="ID">filemenu</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="ID">ID_EXIT</span><span class="Operator">,</span><span class="String">"E&amp;xit"</span><span class="Operator">,</span><span class="String">" Terminate the program"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  79 </span>        <span class="ID">editmenu</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Menu</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  80 </span>        <span class="ID">netmenu</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Menu</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  81 </span>        <span class="ID">showmenu</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Menu</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  82 </span>        <span class="ID">configmenu</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Menu</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  83 </span>        <span class="ID">helpmenu</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Menu</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  84 </span></span>
<span class="line"><span class="LineNumber">  85 </span>        <span class="ID">menuBar</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MenuBar</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  86 </span>        <span class="ID">menuBar</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="ID">filemenu</span><span class="Operator">,</span><span class="String">"&amp;File"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  87 </span>        <span class="ID">menuBar</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="ID">editmenu</span><span class="Operator">,</span> <span class="String">"&amp;Edit"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  88 </span>        <span class="ID">menuBar</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="ID">netmenu</span><span class="Operator">,</span> <span class="String">"&amp;Net"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  89 </span>        <span class="ID">menuBar</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="ID">showmenu</span><span class="Operator">,</span> <span class="String">"&amp;Show"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  90 </span>        <span class="ID">menuBar</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="ID">configmenu</span><span class="Operator">,</span> <span class="String">"&amp;Config"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  91 </span>        <span class="ID">menuBar</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="ID">helpmenu</span><span class="Operator">,</span> <span class="String">"&amp;Help"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  92 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetMenuBar</span><span class="Operator">(</span><span class="ID">menuBar</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  93 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_MENU</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnExit</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="ID">ID_EXIT</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  94 </span></span>
<span class="line"><span class="LineNumber">  95 </span>        <span class="ID">tb</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">CreateToolBar</span><span class="Operator">(</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TB_HORIZONTAL</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">NO_BORDER</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TB_FLAT</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TB_TEXT</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  96 </span>        <span class="ID">tb</span><span class="Operator">.</span><span class="ID">AddSimpleTool</span><span class="Operator">(</span><span class="Number">10</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bitmap</span><span class="Operator">(</span><span class="String">'images/previous.png'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="String">'Previous'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  97 </span>        <span class="ID">tb</span><span class="Operator">.</span><span class="ID">AddSimpleTool</span><span class="Operator">(</span><span class="Number">20</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bitmap</span><span class="Operator">(</span><span class="String">'images/up.png'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="String">'Up one directory'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  98 </span>        <span class="ID">tb</span><span class="Operator">.</span><span class="ID">AddSimpleTool</span><span class="Operator">(</span><span class="Number">30</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bitmap</span><span class="Operator">(</span><span class="String">'images/home.png'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="String">'Home'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  99 </span>        <span class="ID">tb</span><span class="Operator">.</span><span class="ID">AddSimpleTool</span><span class="Operator">(</span><span class="Number">40</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bitmap</span><span class="Operator">(</span><span class="String">'images/refresh.png'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="String">'Refresh'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 100 </span>        <span class="ID">tb</span><span class="Operator">.</span><span class="ID">AddSeparator</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 101 </span>        <span class="ID">tb</span><span class="Operator">.</span><span class="ID">AddSimpleTool</span><span class="Operator">(</span><span class="Number">50</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bitmap</span><span class="Operator">(</span><span class="String">'images/write.png'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="String">'Editor'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 102 </span>        <span class="ID">tb</span><span class="Operator">.</span><span class="ID">AddSimpleTool</span><span class="Operator">(</span><span class="Number">60</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bitmap</span><span class="Operator">(</span><span class="String">'images/terminal.png'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="String">'Terminal'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 103 </span>        <span class="ID">tb</span><span class="Operator">.</span><span class="ID">AddSeparator</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 104 </span>        <span class="ID">tb</span><span class="Operator">.</span><span class="ID">AddSimpleTool</span><span class="Operator">(</span><span class="Number">70</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bitmap</span><span class="Operator">(</span><span class="String">'images/help.png'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="String">'Help'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 105 </span>        <span class="ID">tb</span><span class="Operator">.</span><span class="ID">Realize</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 106 </span></span>
<span class="line"><span class="LineNumber"> 107 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">sizer2</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BoxSizer</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">HORIZONTAL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 108 </span></span>
<span class="line"><span class="LineNumber"> 109 </span>        <span class="ID">button1</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">ID_BUTTON</span> <span class="Operator">+</span> <span class="Number">1</span><span class="Operator">,</span> <span class="String">"F3 View"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 110 </span>        <span class="ID">button2</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">ID_BUTTON</span> <span class="Operator">+</span> <span class="Number">2</span><span class="Operator">,</span> <span class="String">"F4 Edit"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 111 </span>        <span class="ID">button3</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">ID_BUTTON</span> <span class="Operator">+</span> <span class="Number">3</span><span class="Operator">,</span> <span class="String">"F5 Copy"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 112 </span>        <span class="ID">button4</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">ID_BUTTON</span> <span class="Operator">+</span> <span class="Number">4</span><span class="Operator">,</span> <span class="String">"F6 Move"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 113 </span>        <span class="ID">button5</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">ID_BUTTON</span> <span class="Operator">+</span> <span class="Number">5</span><span class="Operator">,</span> <span class="String">"F7 Mkdir"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 114 </span>        <span class="ID">button6</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">ID_BUTTON</span> <span class="Operator">+</span> <span class="Number">6</span><span class="Operator">,</span> <span class="String">"F8 Delete"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 115 </span>        <span class="ID">button7</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">ID_BUTTON</span> <span class="Operator">+</span> <span class="Number">7</span><span class="Operator">,</span> <span class="String">"F9 Rename"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 116 </span>        <span class="ID">button8</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">ID_EXIT</span><span class="Operator">,</span> <span class="String">"F10 Quit"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 117 </span></span>
<span class="line"><span class="LineNumber"> 118 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">sizer2</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">button1</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 119 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">sizer2</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">button2</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 120 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">sizer2</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">button3</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 121 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">sizer2</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">button4</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 122 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">sizer2</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">button5</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 123 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">sizer2</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">button6</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 124 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">sizer2</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">button7</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 125 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">sizer2</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">button8</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 126 </span></span>
<span class="line"><span class="LineNumber"> 127 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnExit</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="ID">ID_EXIT</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 128 </span></span>
<span class="line"><span class="LineNumber"> 129 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">sizer</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BoxSizer</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">VERTICAL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 130 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">sizer</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">splitter</span><span class="Operator">,</span><span class="Number">1</span><span class="Operator">,</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 131 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">sizer</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">sizer2</span><span class="Operator">,</span><span class="Number">0</span><span class="Operator">,</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 132 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetSizer</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">sizer</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 133 </span></span>
<span class="line"><span class="LineNumber"> 134 </span>        <span class="ID">size</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">DisplaySize</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 135 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetSize</span><span class="Operator">(</span><span class="ID">size</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 136 </span></span>
<span class="line"><span class="LineNumber"> 137 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">sb</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">CreateStatusBar</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 138 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">sb</span><span class="Operator">.</span><span class="ID">SetStatusText</span><span class="Operator">(</span><span class="ID">os</span><span class="Operator">.</span><span class="ID">getcwd</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 139 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Center</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 140 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 141 </span></span>
<span class="line"><span class="LineNumber"> 142 </span></span>
<span class="line"><span class="LineNumber"> 143 </span>    <span class="ResWord">def</span> <span class="ID">OnExit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span><span class="ID">e</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 144 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Close</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 145 </span></span>
<span class="line"><span class="LineNumber"> 146 </span>    <span class="ResWord">def</span> <span class="ID">OnSize</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 147 </span>        <span class="ID">size</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">GetSize</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 148 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">splitter</span><span class="Operator">.</span><span class="ID">SetSashPosition</span><span class="Operator">(</span><span class="ID">size</span><span class="Operator">.</span><span class="ID">x</span> <span class="Operator">/</span> <span class="Number">2</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 149 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">sb</span><span class="Operator">.</span><span class="ID">SetStatusText</span><span class="Operator">(</span><span class="ID">os</span><span class="Operator">.</span><span class="ID">getcwd</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 150 </span>        <span class="ID">event</span><span class="Operator">.</span><span class="ID">Skip</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 151 </span></span>
<span class="line"><span class="LineNumber"> 152 </span></span>
<span class="line"><span class="LineNumber"> 153 </span>    <span class="ResWord">def</span> <span class="ID">OnDoubleClick</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 154 </span>        <span class="ID">size</span> <span class="Operator">=</span>  <span class="ID">self</span><span class="Operator">.</span><span class="ID">GetSize</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 155 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">splitter</span><span class="Operator">.</span><span class="ID">SetSashPosition</span><span class="Operator">(</span><span class="ID">size</span><span class="Operator">.</span><span class="ID">x</span> <span class="Operator">/</span> <span class="Number">2</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 156 </span></span>
<span class="line"><span class="LineNumber"> 157 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 158 </span><span class="ID">filehunter</span> <span class="Operator">=</span> <span class="ID">FileHunter</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'File Hunter'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 159 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-4328"></span><p class="line874">If
 you double click on the splitter widget, it will divide the File Hunter
 into two parts with the same width. The same happens, if you resize the
 main window. <span class="anchor" id="line-4329"></span><span class="anchor" id="line-4330"></span></p><p class="line867"><img alt="filehunter.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_041.png" title="filehunter.png"> <span class="anchor" id="line-4331"></span><span class="anchor" id="line-4332"></span></p><p class="line867"><strong>Figure: File Hunter</strong> <span class="anchor" id="line-4333"></span><span class="anchor" id="line-4334"></span></p><p class="line867">
</p><h3 id="SpreadSheet">SpreadSheet</h3>
<span class="anchor" id="line-4335"></span><p class="line874">Gnumeric, 
KSpread andOpenOffice Calc are famous spreadsheet applications available
 on Unix. The following example shows a skeleton of a spreadsheet 
application in wxPython. <span class="anchor" id="line-4336"></span><span class="anchor" id="line-4337"></span></p><p class="line867"><span class="anchor" id="line-4338"></span><span class="anchor" id="line-4339"></span><span class="anchor" id="line-4340"></span><span class="anchor" id="line-4341"></span><span class="anchor" id="line-4342"></span><span class="anchor" id="line-4343"></span><span class="anchor" id="line-4344"></span><span class="anchor" id="line-4345"></span><span class="anchor" id="line-4346"></span><span class="anchor" id="line-4347"></span><span class="anchor" id="line-4348"></span><span class="anchor" id="line-4349"></span><span class="anchor" id="line-4350"></span><span class="anchor" id="line-4351"></span><span class="anchor" id="line-4352"></span><span class="anchor" id="line-4353"></span><span class="anchor" id="line-4354"></span><span class="anchor" id="line-4355"></span><span class="anchor" id="line-4356"></span><span class="anchor" id="line-4357"></span><span class="anchor" id="line-4358"></span><span class="anchor" id="line-4359"></span><span class="anchor" id="line-4360"></span><span class="anchor" id="line-4361"></span><span class="anchor" id="line-4362"></span><span class="anchor" id="line-4363"></span><span class="anchor" id="line-4364"></span><span class="anchor" id="line-4365"></span><span class="anchor" id="line-4366"></span><span class="anchor" id="line-4367"></span><span class="anchor" id="line-4368"></span><span class="anchor" id="line-4369"></span><span class="anchor" id="line-4370"></span><span class="anchor" id="line-4371"></span><span class="anchor" id="line-4372"></span><span class="anchor" id="line-4373"></span><span class="anchor" id="line-4374"></span><span class="anchor" id="line-4375"></span><span class="anchor" id="line-4376"></span><span class="anchor" id="line-4377"></span><span class="anchor" id="line-4378"></span><span class="anchor" id="line-4379"></span><span class="anchor" id="line-4380"></span><span class="anchor" id="line-4381"></span><span class="anchor" id="line-4382"></span><span class="anchor" id="line-4383"></span><span class="anchor" id="line-4384"></span><span class="anchor" id="line-4385"></span><span class="anchor" id="line-4386"></span><span class="anchor" id="line-4387"></span><span class="anchor" id="line-4388"></span><span class="anchor" id="line-4389"></span><span class="anchor" id="line-4390"></span><span class="anchor" id="line-4391"></span><span class="anchor" id="line-4392"></span><span class="anchor" id="line-4393"></span><span class="anchor" id="line-4394"></span><span class="anchor" id="line-4395"></span><span class="anchor" id="line-4396"></span><span class="anchor" id="line-4397"></span><span class="anchor" id="line-4398"></span><span class="anchor" id="line-4399"></span><span class="anchor" id="line-4400"></span><span class="anchor" id="line-4401"></span><span class="anchor" id="line-4402"></span><span class="anchor" id="line-4403"></span><span class="anchor" id="line-4404"></span><span class="anchor" id="line-4405"></span><span class="anchor" id="line-4406"></span><span class="anchor" id="line-4407"></span><span class="anchor" id="line-4408"></span><span class="anchor" id="line-4409"></span><span class="anchor" id="line-4410"></span><span class="anchor" id="line-4411"></span><span class="anchor" id="line-4412"></span><span class="anchor" id="line-4413"></span><span class="anchor" id="line-4414"></span><span class="anchor" id="line-4415"></span><span class="anchor" id="line-4416"></span><span class="anchor" id="line-4417"></span><span class="anchor" id="line-4418"></span><span class="anchor" id="line-4419"></span><span class="anchor" id="line-4420"></span><span class="anchor" id="line-4421"></span><span class="anchor" id="line-4422"></span><span class="anchor" id="line-4423"></span><span class="anchor" id="line-4424"></span><span class="anchor" id="line-4425"></span><span class="anchor" id="line-4426"></span><span class="anchor" id="line-4427"></span><span class="anchor" id="line-4428"></span><span class="anchor" id="line-4429"></span><span class="anchor" id="line-4430"></span><span class="anchor" id="line-4431"></span><span class="anchor" id="line-4432"></span><span class="anchor" id="line-4433"></span><span class="anchor" id="line-4434"></span><span class="anchor" id="line-4435"></span><span class="anchor" id="line-4436"></span><span class="anchor" id="line-4437"></span><span class="anchor" id="line-4438"></span><span class="anchor" id="line-4439"></span><span class="anchor" id="line-4440"></span><span class="anchor" id="line-4441"></span><span class="anchor" id="line-4442"></span><span class="anchor" id="line-4443"></span><span class="anchor" id="line-4444"></span><span class="anchor" id="line-4445"></span><span class="anchor" id="line-4446"></span><span class="anchor" id="line-4447"></span><span class="anchor" id="line-4448"></span><span class="anchor" id="line-4449"></span><span class="anchor" id="line-4450"></span><span class="anchor" id="line-4451"></span><span class="anchor" id="line-4452"></span><span class="anchor" id="line-4453"></span><span class="anchor" id="line-4454"></span><span class="anchor" id="line-4455"></span><span class="anchor" id="line-4456"></span><span class="anchor" id="line-4457"></span><span class="anchor" id="line-4458"></span><span class="anchor" id="line-4459"></span><span class="anchor" id="line-4460"></span><span class="anchor" id="line-4461"></span><span class="anchor" id="line-4462"></span><span class="anchor" id="line-4463"></span><span class="anchor" id="line-4464"></span><span class="anchor" id="line-4465"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-1c3560b1104294fe7a934f4c6efa5f2342e99259\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-1c3560b1104294fe7a934f4c6efa5f2342e99259', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-1c3560b1104294fe7a934f4c6efa5f2342e99259" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># spreadsheet.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">from</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">lib</span> <span class="ResWord">import</span> <span class="ID">sheet</span></span>
<span class="line"><span class="LineNumber">   6 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   7 </span></span>
<span class="line"><span class="LineNumber">   8 </span></span>
<span class="line"><span class="LineNumber">   9 </span><span class="ResWord">class</span> <span class="ID">MySheet</span><span class="Operator">(</span><span class="ID">sheet</span><span class="Operator">.</span><span class="ID">CSheet</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  10 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  11 </span>        <span class="ID">sheet</span><span class="Operator">.</span><span class="ID">CSheet</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">row</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">col</span> <span class="Operator">=</span> <span class="Number">0</span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetNumberRows</span><span class="Operator">(</span><span class="Number">55</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetNumberCols</span><span class="Operator">(</span><span class="Number">25</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span></span>
<span class="line"><span class="LineNumber">  16 </span>        <span class="ResWord">for</span> <span class="ID">i</span> <span class="ResWord">in</span> <span class="ID">range</span><span class="Operator">(</span><span class="Number">55</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  17 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetRowSize</span><span class="Operator">(</span><span class="ID">i</span><span class="Operator">,</span> <span class="Number">20</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  18 </span></span>
<span class="line"><span class="LineNumber">  19 </span>    <span class="ResWord">def</span> <span class="ID">OnGridSelectCell</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  20 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">row</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">col</span> <span class="Operator">=</span> <span class="ID">event</span><span class="Operator">.</span><span class="ID">GetRow</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">.</span><span class="ID">GetCol</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  21 </span>        <span class="ID">control</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">GetParent</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">.</span><span class="ID">GetParent</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">.</span><span class="ID">position</span></span>
<span class="line"><span class="LineNumber">  22 </span>        <span class="ID">value</span> <span class="Operator">=</span>  <span class="ID">self</span><span class="Operator">.</span><span class="ID">GetColLabelValue</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">col</span><span class="Operator">)</span> <span class="Operator">+</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">GetRowLabelValue</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">row</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  23 </span>        <span class="ID">control</span><span class="Operator">.</span><span class="ID">SetValue</span><span class="Operator">(</span><span class="ID">value</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  24 </span>        <span class="ID">event</span><span class="Operator">.</span><span class="ID">Skip</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  25 </span></span>
<span class="line"><span class="LineNumber">  26 </span></span>
<span class="line"><span class="LineNumber">  27 </span><span class="ResWord">class</span> <span class="ID">Newt</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  28 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  29 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">size</span> <span class="Operator">=</span> <span class="Operator">(</span> <span class="Number">550</span><span class="Operator">,</span> <span class="Number">500</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  30 </span></span>
<span class="line"><span class="LineNumber">  31 </span>        <span class="ID">fonts</span> <span class="Operator">=</span> <span class="Operator">[</span><span class="String">'Times New Roman'</span><span class="Operator">,</span> <span class="String">'Times'</span><span class="Operator">,</span> <span class="String">'Courier'</span><span class="Operator">,</span> <span class="String">'Courier New'</span><span class="Operator">,</span> <span class="String">'Helvetica'</span><span class="Operator">,</span> <span class="String">'Sans'</span><span class="Operator">,</span> <span class="String">'verdana'</span><span class="Operator">,</span> <span class="String">'utkal'</span><span class="Operator">,</span> <span class="String">'aakar'</span><span class="Operator">,</span> <span class="String">'Arial'</span><span class="Operator">]</span></span>
<span class="line"><span class="LineNumber">  32 </span>        <span class="ID">box</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BoxSizer</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">VERTICAL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  33 </span>        <span class="ID">menuBar</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MenuBar</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  34 </span></span>
<span class="line"><span class="LineNumber">  35 </span>        <span class="ID">menu1</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Menu</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  36 </span>        <span class="ID">menuBar</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="ID">menu1</span><span class="Operator">,</span> <span class="String">'&amp;File'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  37 </span>        <span class="ID">menu2</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Menu</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  38 </span>        <span class="ID">menuBar</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="ID">menu2</span><span class="Operator">,</span> <span class="String">'&amp;Edit'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  39 </span>        <span class="ID">menu3</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Menu</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  40 </span>        <span class="ID">menuBar</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="ID">menu3</span><span class="Operator">,</span> <span class="String">'&amp;Edit'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  41 </span>        <span class="ID">menu4</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Menu</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  42 </span>        <span class="ID">menuBar</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="ID">menu4</span><span class="Operator">,</span> <span class="String">'&amp;Insert'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  43 </span>        <span class="ID">menu5</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Menu</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  44 </span>        <span class="ID">menuBar</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="ID">menu5</span><span class="Operator">,</span> <span class="String">'F&amp;ormat'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  45 </span>        <span class="ID">menu6</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Menu</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  46 </span>        <span class="ID">menuBar</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="ID">menu6</span><span class="Operator">,</span> <span class="String">'&amp;Tools'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  47 </span>        <span class="ID">menu7</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Menu</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  48 </span>        <span class="ID">menuBar</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="ID">menu7</span><span class="Operator">,</span> <span class="String">'&amp;Data'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  49 </span></span>
<span class="line"><span class="LineNumber">  50 </span>        <span class="ID">menu7</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Menu</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  51 </span>        <span class="ID">menuBar</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="ID">menu7</span><span class="Operator">,</span> <span class="String">'&amp;Help'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  52 </span></span>
<span class="line"><span class="LineNumber">  53 </span></span>
<span class="line"><span class="LineNumber">  54 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetMenuBar</span><span class="Operator">(</span><span class="ID">menuBar</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  55 </span></span>
<span class="line"><span class="LineNumber">  56 </span>        <span class="ID">toolbar1</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ToolBar</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TB_HORIZONTAL</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">NO_BORDER</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TB_FLAT</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TB_TEXT</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  57 </span>        <span class="ID">toolbar1</span><span class="Operator">.</span><span class="ID">AddSimpleTool</span><span class="Operator">(</span><span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Image</span><span class="Operator">(</span><span class="String">'icons/stock_new.png'</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BITMAP_TYPE_PNG</span><span class="Operator">)</span><span class="Operator">.</span><span class="ID">ConvertToBitmap</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">,</span> <span class="String">'New'</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  58 </span>        <span class="ID">toolbar1</span><span class="Operator">.</span><span class="ID">AddSimpleTool</span><span class="Operator">(</span><span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Image</span><span class="Operator">(</span><span class="String">'icons/stock_open.png'</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BITMAP_TYPE_PNG</span><span class="Operator">)</span><span class="Operator">.</span><span class="ID">ConvertToBitmap</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">,</span> <span class="String">'Open'</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  59 </span>        <span class="ID">toolbar1</span><span class="Operator">.</span><span class="ID">AddSimpleTool</span><span class="Operator">(</span><span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Image</span><span class="Operator">(</span><span class="String">'icons/stock_save.png'</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BITMAP_TYPE_PNG</span><span class="Operator">)</span><span class="Operator">.</span><span class="ID">ConvertToBitmap</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">,</span> <span class="String">'Save'</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  60 </span>        <span class="ID">toolbar1</span><span class="Operator">.</span><span class="ID">AddSeparator</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  61 </span>        <span class="ID">toolbar1</span><span class="Operator">.</span><span class="ID">AddSimpleTool</span><span class="Operator">(</span><span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Image</span><span class="Operator">(</span><span class="String">'icons/stock_cut.png'</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BITMAP_TYPE_PNG</span><span class="Operator">)</span><span class="Operator">.</span><span class="ID">ConvertToBitmap</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">,</span> <span class="String">'Cut'</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  62 </span>        <span class="ID">toolbar1</span><span class="Operator">.</span><span class="ID">AddSimpleTool</span><span class="Operator">(</span><span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Image</span><span class="Operator">(</span><span class="String">'icons/stock_copy.png'</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BITMAP_TYPE_PNG</span><span class="Operator">)</span><span class="Operator">.</span><span class="ID">ConvertToBitmap</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">,</span> <span class="String">'Copy'</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  63 </span>        <span class="ID">toolbar1</span><span class="Operator">.</span><span class="ID">AddSimpleTool</span><span class="Operator">(</span><span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Image</span><span class="Operator">(</span><span class="String">'icons/stock_paste.png'</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BITMAP_TYPE_PNG</span><span class="Operator">)</span><span class="Operator">.</span><span class="ID">ConvertToBitmap</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">,</span> <span class="String">'Paste'</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  64 </span>        <span class="ID">toolbar1</span><span class="Operator">.</span><span class="ID">AddSimpleTool</span><span class="Operator">(</span><span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Image</span><span class="Operator">(</span><span class="String">'icons/stock_delete.png'</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BITMAP_TYPE_PNG</span><span class="Operator">)</span><span class="Operator">.</span><span class="ID">ConvertToBitmap</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">,</span> <span class="String">'Delete'</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  65 </span>        <span class="ID">toolbar1</span><span class="Operator">.</span><span class="ID">AddSeparator</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  66 </span>        <span class="ID">toolbar1</span><span class="Operator">.</span><span class="ID">AddSimpleTool</span><span class="Operator">(</span><span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Image</span><span class="Operator">(</span><span class="String">'icons/stock_undo.png'</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BITMAP_TYPE_PNG</span><span class="Operator">)</span><span class="Operator">.</span><span class="ID">ConvertToBitmap</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">,</span> <span class="String">'Undo'</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  67 </span>        <span class="ID">toolbar1</span><span class="Operator">.</span><span class="ID">AddSimpleTool</span><span class="Operator">(</span><span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Image</span><span class="Operator">(</span><span class="String">'icons/stock_redo.png'</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BITMAP_TYPE_PNG</span><span class="Operator">)</span><span class="Operator">.</span><span class="ID">ConvertToBitmap</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">,</span> <span class="String">'Redo'</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  68 </span>        <span class="ID">toolbar1</span><span class="Operator">.</span><span class="ID">AddSeparator</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  69 </span>        <span class="ID">toolbar1</span><span class="Operator">.</span><span class="ID">AddSimpleTool</span><span class="Operator">(</span><span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Image</span><span class="Operator">(</span><span class="String">'icons/incr22.png'</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BITMAP_TYPE_PNG</span><span class="Operator">)</span><span class="Operator">.</span><span class="ID">ConvertToBitmap</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">,</span> <span class="String">'Sort Increasing'</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  70 </span>        <span class="ID">toolbar1</span><span class="Operator">.</span><span class="ID">AddSimpleTool</span><span class="Operator">(</span><span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Image</span><span class="Operator">(</span><span class="String">'icons/decr22.png'</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BITMAP_TYPE_PNG</span><span class="Operator">)</span><span class="Operator">.</span><span class="ID">ConvertToBitmap</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">,</span> <span class="String">'Sort Decreasing'</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  71 </span>        <span class="ID">toolbar1</span><span class="Operator">.</span><span class="ID">AddSeparator</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  72 </span>        <span class="ID">toolbar1</span><span class="Operator">.</span><span class="ID">AddSimpleTool</span><span class="Operator">(</span><span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Image</span><span class="Operator">(</span><span class="String">'icons/graph_guru_24.xpm'</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BITMAP_TYPE_XPM</span><span class="Operator">)</span><span class="Operator">.</span><span class="ID">ConvertToBitmap</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">,</span> <span class="String">'Chart'</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  73 </span>        <span class="ID">toolbar1</span><span class="Operator">.</span><span class="ID">AddSeparator</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  74 </span>        <span class="ID">toolbar1</span><span class="Operator">.</span><span class="ID">AddSimpleTool</span><span class="Operator">(</span><span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Image</span><span class="Operator">(</span><span class="String">'icons/stock_exit.png'</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BITMAP_TYPE_PNG</span><span class="Operator">)</span><span class="Operator">.</span><span class="ID">ConvertToBitmap</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">,</span> <span class="String">'Quit'</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  75 </span></span>
<span class="line"><span class="LineNumber">  76 </span>        <span class="ID">toolbar1</span><span class="Operator">.</span><span class="ID">Realize</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  77 </span></span>
<span class="line"><span class="LineNumber">  78 </span>        <span class="ID">toolbar2</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ToolBar</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TB_HORIZONTAL</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TB_TEXT</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  79 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">position</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TextCtrl</span><span class="Operator">(</span><span class="ID">toolbar2</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  80 </span>        <span class="ID">font</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ComboBox</span><span class="Operator">(</span><span class="ID">toolbar2</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">value</span> <span class="Operator">=</span> <span class="String">'Times'</span><span class="Operator">,</span> <span class="ID">choices</span><span class="Operator">=</span><span class="ID">fonts</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">100</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">CB_DROPDOWN</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  81 </span>        <span class="ID">font_height</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ComboBox</span><span class="Operator">(</span><span class="ID">toolbar2</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">value</span> <span class="Operator">=</span> <span class="String">'10'</span><span class="Operator">,</span>  <span class="ID">choices</span><span class="Operator">=</span><span class="Operator">[</span><span class="String">'10'</span><span class="Operator">,</span> <span class="String">'11'</span><span class="Operator">,</span> <span class="String">'12'</span><span class="Operator">,</span> <span class="String">'14'</span><span class="Operator">,</span> <span class="String">'16'</span><span class="Operator">]</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">50</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">CB_DROPDOWN</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  82 </span>        <span class="ID">toolbar2</span><span class="Operator">.</span><span class="ID">AddControl</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">position</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  83 </span>        <span class="ID">toolbar2</span><span class="Operator">.</span><span class="ID">AddControl</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">toolbar2</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'  '</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  84 </span>        <span class="ID">toolbar2</span><span class="Operator">.</span><span class="ID">AddControl</span><span class="Operator">(</span><span class="ID">font</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  85 </span>        <span class="ID">toolbar2</span><span class="Operator">.</span><span class="ID">AddControl</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">toolbar2</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'  '</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  86 </span>        <span class="ID">toolbar2</span><span class="Operator">.</span><span class="ID">AddControl</span><span class="Operator">(</span><span class="ID">font_height</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  87 </span>        <span class="ID">toolbar2</span><span class="Operator">.</span><span class="ID">AddSeparator</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  88 </span>        <span class="ID">bold</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Image</span><span class="Operator">(</span><span class="String">'icons/stock_text_bold.png'</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BITMAP_TYPE_PNG</span><span class="Operator">)</span><span class="Operator">.</span><span class="ID">ConvertToBitmap</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  89 </span>        <span class="ID">toolbar2</span><span class="Operator">.</span><span class="ID">AddCheckTool</span><span class="Operator">(</span><span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">bold</span> <span class="Operator">,</span> <span class="ID">shortHelp</span> <span class="Operator">=</span> <span class="String">'Bold'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  90 </span>        <span class="ID">italic</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Image</span><span class="Operator">(</span><span class="String">'icons/stock_text_italic.png'</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BITMAP_TYPE_PNG</span><span class="Operator">)</span><span class="Operator">.</span><span class="ID">ConvertToBitmap</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  91 </span>        <span class="ID">toolbar2</span><span class="Operator">.</span><span class="ID">AddCheckTool</span><span class="Operator">(</span><span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">italic</span><span class="Operator">,</span>  <span class="ID">shortHelp</span> <span class="Operator">=</span> <span class="String">'Italic'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  92 </span>        <span class="ID">under</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Image</span><span class="Operator">(</span><span class="String">'icons/stock_text_underline.png'</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BITMAP_TYPE_PNG</span><span class="Operator">)</span><span class="Operator">.</span><span class="ID">ConvertToBitmap</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  93 </span>        <span class="ID">toolbar2</span><span class="Operator">.</span><span class="ID">AddCheckTool</span><span class="Operator">(</span><span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">under</span><span class="Operator">,</span> <span class="ID">shortHelp</span> <span class="Operator">=</span> <span class="String">'Underline'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  94 </span>        <span class="ID">toolbar2</span><span class="Operator">.</span><span class="ID">AddSeparator</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  95 </span>        <span class="ID">toolbar2</span><span class="Operator">.</span><span class="ID">AddSimpleTool</span><span class="Operator">(</span><span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Image</span><span class="Operator">(</span><span class="String">'icons/stock_text_align_left.png'</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BITMAP_TYPE_PNG</span><span class="Operator">)</span><span class="Operator">.</span><span class="ID">ConvertToBitmap</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">,</span> <span class="String">'Align Left'</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  96 </span>        <span class="ID">toolbar2</span><span class="Operator">.</span><span class="ID">AddSimpleTool</span><span class="Operator">(</span><span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Image</span><span class="Operator">(</span><span class="String">'icons/stock_text_align_center.png'</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BITMAP_TYPE_PNG</span><span class="Operator">)</span><span class="Operator">.</span><span class="ID">ConvertToBitmap</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">,</span> <span class="String">'Center'</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  97 </span>        <span class="ID">toolbar2</span><span class="Operator">.</span><span class="ID">AddSimpleTool</span><span class="Operator">(</span><span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Image</span><span class="Operator">(</span><span class="String">'icons/stock_text_align_right.png'</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BITMAP_TYPE_PNG</span><span class="Operator">)</span><span class="Operator">.</span><span class="ID">ConvertToBitmap</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">,</span> <span class="String">'Align Right'</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  98 </span></span>
<span class="line"><span class="LineNumber">  99 </span>        <span class="ID">box</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">toolbar1</span><span class="Operator">,</span> <span class="ID">border</span><span class="Operator">=</span><span class="Number">5</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 100 </span>        <span class="ID">box</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="Operator">(</span><span class="Number">5</span><span class="Operator">,</span><span class="Number">5</span><span class="Operator">)</span> <span class="Operator">,</span> <span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 101 </span>        <span class="ID">box</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">toolbar2</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 102 </span>        <span class="ID">box</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="Operator">(</span><span class="Number">5</span><span class="Operator">,</span><span class="Number">10</span><span class="Operator">)</span> <span class="Operator">,</span> <span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 103 </span></span>
<span class="line"><span class="LineNumber"> 104 </span>        <span class="ID">toolbar2</span><span class="Operator">.</span><span class="ID">Realize</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 105 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetSizer</span><span class="Operator">(</span><span class="ID">box</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 106 </span>        <span class="ID">notebook</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Notebook</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">BOTTOM</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 107 </span></span>
<span class="line"><span class="LineNumber"> 108 </span>        <span class="ID">sheet1</span> <span class="Operator">=</span> <span class="ID">MySheet</span><span class="Operator">(</span><span class="ID">notebook</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 109 </span>        <span class="ID">sheet2</span> <span class="Operator">=</span> <span class="ID">MySheet</span><span class="Operator">(</span><span class="ID">notebook</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 110 </span>        <span class="ID">sheet3</span> <span class="Operator">=</span> <span class="ID">MySheet</span><span class="Operator">(</span><span class="ID">notebook</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 111 </span>        <span class="ID">sheet1</span><span class="Operator">.</span><span class="ID">SetFocus</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 112 </span></span>
<span class="line"><span class="LineNumber"> 113 </span>        <span class="ID">notebook</span><span class="Operator">.</span><span class="ID">AddPage</span><span class="Operator">(</span><span class="ID">sheet1</span><span class="Operator">,</span> <span class="String">'Sheet1'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 114 </span>        <span class="ID">notebook</span><span class="Operator">.</span><span class="ID">AddPage</span><span class="Operator">(</span><span class="ID">sheet2</span><span class="Operator">,</span> <span class="String">'Sheet2'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 115 </span>        <span class="ID">notebook</span><span class="Operator">.</span><span class="ID">AddPage</span><span class="Operator">(</span><span class="ID">sheet3</span><span class="Operator">,</span> <span class="String">'Sheet3'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 116 </span></span>
<span class="line"><span class="LineNumber"> 117 </span>        <span class="ID">box</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">notebook</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 118 </span></span>
<span class="line"><span class="LineNumber"> 119 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">CreateStatusBar</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 120 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 121 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 122 </span></span>
<span class="line"><span class="LineNumber"> 123 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 124 </span><span class="ID">newt</span> <span class="Operator">=</span> <span class="ID">Newt</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'SpreadSheet'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 125 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-4466"></span><p class="line867"><img alt="spreadsheet.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_017.png" title="spreadsheet.png"> <span class="anchor" id="line-4467"></span><span class="anchor" id="line-4468"></span></p><p class="line867"><strong>Figure: spreadsheet.py</strong> <span class="anchor" id="line-4469"></span><span class="anchor" id="line-4470"></span></p><p class="line867">
</p><h2 id="Tips_And_Tricks">Tips And Tricks</h2>
<span class="anchor" id="line-4471"></span><p class="line874">In this section we will show some tips in wxPython. <span class="anchor" id="line-4472"></span><span class="anchor" id="line-4473"></span></p><p class="line867">
</p><h3 id="PopupMenu">PopupMenu</h3>
<span class="anchor" id="line-4474"></span><p class="line874">The 
following code was committed by Chris Barker on the wxPython-users 
mailing list. Popup menu is here implemented in a separate class. This 
way, you don't have to manually check, if the events were already bound.
 <span class="anchor" id="line-4475"></span><span class="anchor" id="line-4476"></span></p><p class="line867"><span class="anchor" id="line-4477"></span><span class="anchor" id="line-4478"></span><span class="anchor" id="line-4479"></span><span class="anchor" id="line-4480"></span><span class="anchor" id="line-4481"></span><span class="anchor" id="line-4482"></span><span class="anchor" id="line-4483"></span><span class="anchor" id="line-4484"></span><span class="anchor" id="line-4485"></span><span class="anchor" id="line-4486"></span><span class="anchor" id="line-4487"></span><span class="anchor" id="line-4488"></span><span class="anchor" id="line-4489"></span><span class="anchor" id="line-4490"></span><span class="anchor" id="line-4491"></span><span class="anchor" id="line-4492"></span><span class="anchor" id="line-4493"></span><span class="anchor" id="line-4494"></span><span class="anchor" id="line-4495"></span><span class="anchor" id="line-4496"></span><span class="anchor" id="line-4497"></span><span class="anchor" id="line-4498"></span><span class="anchor" id="line-4499"></span><span class="anchor" id="line-4500"></span><span class="anchor" id="line-4501"></span><span class="anchor" id="line-4502"></span><span class="anchor" id="line-4503"></span><span class="anchor" id="line-4504"></span><span class="anchor" id="line-4505"></span><span class="anchor" id="line-4506"></span><span class="anchor" id="line-4507"></span><span class="anchor" id="line-4508"></span><span class="anchor" id="line-4509"></span><span class="anchor" id="line-4510"></span><span class="anchor" id="line-4511"></span><span class="anchor" id="line-4512"></span><span class="anchor" id="line-4513"></span><span class="anchor" id="line-4514"></span><span class="anchor" id="line-4515"></span><span class="anchor" id="line-4516"></span><span class="anchor" id="line-4517"></span><span class="anchor" id="line-4518"></span><span class="anchor" id="line-4519"></span><span class="anchor" id="line-4520"></span><span class="anchor" id="line-4521"></span><span class="anchor" id="line-4522"></span><span class="anchor" id="line-4523"></span><span class="anchor" id="line-4524"></span><span class="anchor" id="line-4525"></span><span class="anchor" id="line-4526"></span><span class="anchor" id="line-4527"></span><span class="anchor" id="line-4528"></span><span class="anchor" id="line-4529"></span><span class="anchor" id="line-4530"></span><span class="anchor" id="line-4531"></span><span class="anchor" id="line-4532"></span><span class="anchor" id="line-4533"></span><span class="anchor" id="line-4534"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-91c40764ecfd09cb6890dbac4054793a057b6097\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-91c40764ecfd09cb6890dbac4054793a057b6097', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-91c40764ecfd09cb6890dbac4054793a057b6097" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/env python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># popup.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">PySimpleApp</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">   8 </span></span>
<span class="line"><span class="LineNumber">   9 </span><span class="ResWord">class</span> <span class="ID">MyPopupMenu</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Menu</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  10 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">WinName</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  11 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Menu</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  12 </span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">WinName</span> <span class="Operator">=</span> <span class="ID">WinName</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">item</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MenuItem</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">NewId</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">,</span> <span class="String">"Item One"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">item</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_MENU</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnItem1</span><span class="Operator">,</span> <span class="ID">item</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="ID">item</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MenuItem</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">NewId</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">,</span><span class="String">"Item Two"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  18 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">item</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  19 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_MENU</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnItem2</span><span class="Operator">,</span> <span class="ID">item</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  20 </span>        <span class="ID">item</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MenuItem</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">NewId</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">,</span><span class="String">"Item Three"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  21 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">item</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  22 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_MENU</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnItem3</span><span class="Operator">,</span> <span class="ID">item</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  23 </span></span>
<span class="line"><span class="LineNumber">  24 </span>    <span class="ResWord">def</span> <span class="ID">OnItem1</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  25 </span>        <span class="ResWord">print</span> <span class="String">"Item One selected in the %s window"</span><span class="Operator">%</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">WinName</span></span>
<span class="line"><span class="LineNumber">  26 </span></span>
<span class="line"><span class="LineNumber">  27 </span>    <span class="ResWord">def</span> <span class="ID">OnItem2</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  28 </span>        <span class="ResWord">print</span> <span class="String">"Item Two selected in the %s window"</span><span class="Operator">%</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">WinName</span></span>
<span class="line"><span class="LineNumber">  29 </span></span>
<span class="line"><span class="LineNumber">  30 </span>    <span class="ResWord">def</span> <span class="ID">OnItem3</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  31 </span>        <span class="ResWord">print</span> <span class="String">"Item Three selected in the %s window"</span><span class="Operator">%</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">WinName</span></span>
<span class="line"><span class="LineNumber">  32 </span></span>
<span class="line"><span class="LineNumber">  33 </span><span class="ResWord">class</span> <span class="ID">MyWindow</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Window</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  34 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">color</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  35 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Window</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  36 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">color</span> <span class="Operator">=</span> <span class="ID">color</span></span>
<span class="line"><span class="LineNumber">  37 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetBackgroundColour</span><span class="Operator">(</span><span class="ID">color</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  38 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_RIGHT_DOWN</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnRightDown</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  39 </span></span>
<span class="line"><span class="LineNumber">  40 </span>    <span class="ResWord">def</span> <span class="ID">OnRightDown</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span><span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  41 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">PopupMenu</span><span class="Operator">(</span><span class="ID">MyPopupMenu</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">color</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">.</span><span class="ID">GetPosition</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  42 </span></span>
<span class="line"><span class="LineNumber">  43 </span><span class="ResWord">class</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  44 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  45 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">"Test"</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">300</span><span class="Operator">,</span> <span class="Number">200</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  46 </span>        <span class="ID">sizer</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">GridSizer</span><span class="Operator">(</span><span class="Number">2</span><span class="Operator">,</span><span class="Number">2</span><span class="Operator">,</span><span class="Number">5</span><span class="Operator">,</span><span class="Number">5</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  47 </span>        <span class="ID">sizer</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">MyWindow</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span><span class="String">"blue"</span><span class="Operator">)</span><span class="Operator">,</span><span class="Number">1</span><span class="Operator">,</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">GROW</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  48 </span>        <span class="ID">sizer</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">MyWindow</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span><span class="String">"yellow"</span><span class="Operator">)</span><span class="Operator">,</span><span class="Number">1</span><span class="Operator">,</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">GROW</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  49 </span>        <span class="ID">sizer</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">MyWindow</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span><span class="String">"red"</span><span class="Operator">)</span><span class="Operator">,</span><span class="Number">1</span><span class="Operator">,</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">GROW</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  50 </span>        <span class="ID">sizer</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">MyWindow</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span><span class="String">"green"</span><span class="Operator">)</span><span class="Operator">,</span><span class="Number">1</span><span class="Operator">,</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">GROW</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  51 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetSizer</span><span class="Operator">(</span><span class="ID">sizer</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  52 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  53 </span></span>
<span class="line"><span class="LineNumber">  54 </span><span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  55 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">SetTopWindow</span><span class="Operator">(</span><span class="ID">frame</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  56 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-4535"></span><p class="line874">The
 example is just a single frame. This frame is divided into four 
windows.  If you right click on the frame, context menu pops up. Context
 menu consists of three commands. If you select any of them a message is
 sent to the console. It will say what item you selected plus the color 
of the window where you clicked with the mouse. This example shows the 
power of  the object oriented programming. Imagine you would have to do 
it the other way, by calculating manually the position of the pointer! <span class="anchor" id="line-4536"></span><span class="anchor" id="line-4537"></span></p><p class="line874">Notice
 that the popup menu is implemented as a new class.  This is a more 
elegant way of using popup menus as the following one, taken from the 
Demo application. <span class="anchor" id="line-4538"></span><span class="anchor" id="line-4539"></span></p><p class="line867"><span class="anchor" id="line-4540"></span><span class="anchor" id="line-4541"></span><span class="anchor" id="line-4542"></span><span class="anchor" id="line-4543"></span><span class="anchor" id="line-4544"></span><span class="anchor" id="line-4545"></span><span class="anchor" id="line-4546"></span><span class="anchor" id="line-4547"></span><span class="anchor" id="line-4548"></span><span class="anchor" id="line-4549"></span><span class="anchor" id="line-4550"></span><span class="anchor" id="line-4551"></span><span class="anchor" id="line-4552"></span><span class="anchor" id="line-4553"></span><span class="anchor" id="line-4554"></span><span class="anchor" id="line-4555"></span><span class="anchor" id="line-4556"></span></p><pre> def OnRightClick(self, event):
        # only do this part the first time so the events are only bound once
        if not hasattr(self, "popupID1"):
            self.popupID1 = wx.NewId()
            self.popupID2 = wx.NewId()
            self.Bind(wx.EVT_MENU, self.OnPopupOne, id=self.popupID1)
            self.Bind(wx.EVT_MENU, self.OnPopupTwo, id=self.popupID2)
        menu = wx.Menu()
        menu.Append(self.popupID1, "One")
        menu.Append(self.popupID2, "Two")
        self.PopupMenu(menu, event.GetPosition())
        menu.Destroy()
    def OnPopupOne(self, event):
        pass
    def OnPopupTwo(self, event):
        pass</pre><span class="anchor" id="line-4557"></span><p class="line874">There
 is one subtle thing in the code that needs some clarification. You only
 boud an  event once. It resides in event table afterwards. If it is 
done in the constructor, everything is ok.  But when you bound an event 
to a method in a method, you do it everytime when the method gets 
invoked. That's why we wrote a condition to ensure, we don't implement 
this overhead. <span class="anchor" id="line-4558"></span><span class="anchor" id="line-4559"></span></p><p class="line867"><span class="anchor" id="line-4560"></span><span class="anchor" id="line-4561"></span><span class="anchor" id="line-4562"></span><span class="anchor" id="line-4563"></span><span class="anchor" id="line-4564"></span><span class="anchor" id="line-4565"></span></p><pre> if not hasattr(self, "popupID1"):
            self.popupID1 = wx.NewId()
            self.popupID2 = wx.NewId()
            self.Bind(wx.EVT_MENU, self.OnPopupOne, id=self.popupID1)
            self.Bind(wx.EVT_MENU, self.OnPopupTwo, id=self.popupID2)</pre><span class="anchor" id="line-4566"></span><p class="line867">
</p><h3 id="The_tiniest_wxPython_application">The tiniest wxPython application</h3>
<span class="anchor" id="line-4567"></span><p class="line874">Feel free to contact me, if you can shorthen it. Even for one single character. <span class="anchor" id="line-4568"></span><span class="anchor" id="line-4569"></span></p><p class="line867"><span class="anchor" id="line-4570"></span><span class="anchor" id="line-4571"></span><span class="anchor" id="line-4572"></span><span class="anchor" id="line-4573"></span><span class="anchor" id="line-4574"></span><span class="anchor" id="line-4575"></span><span class="anchor" id="line-4576"></span><span class="anchor" id="line-4577"></span><span class="anchor" id="line-4578"></span><span class="anchor" id="line-4579"></span><span class="anchor" id="line-4580"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-ef0ba33f4f03f14d6dc3d20c59ecae61de851eb3\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-ef0ba33f4f03f14d6dc3d20c59ecae61de851eb3', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-ef0ba33f4f03f14d6dc3d20c59ecae61de851eb3" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   4 </span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ID">i</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">)</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">   8 </span></span>
<span class="line"><span class="LineNumber">   9 </span><span class="ID">i</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-4581"></span><p class="line867">
</p><h3 id="Interactive_Button">Interactive Button</h3>
<span class="anchor" id="line-4582"></span><p class="line874">This tip 
shows how to program an interactive Button. This button reacts to users 
actions. In our case, the button changes it's background colour. When 
you enter the area of the button widget with a mouse pointer, <span class="anchor" id="line-4583"></span><span class="anchor" id="line-4584"></span></p><p class="line867"><tt>EVT_ENTER_WINDOW</tt> event is generated. Simirarly, <tt>EVT_LEAVE_WINDOW</tt>
 event is generated, when you leave the area of the widget. So all you 
have to do is to bind those events to functions, that will change the 
colour/shape of the button widget appropriately. <span class="anchor" id="line-4585"></span><span class="anchor" id="line-4586"></span></p><p class="line867"><span class="anchor" id="line-4587"></span><span class="anchor" id="line-4588"></span><span class="anchor" id="line-4589"></span><span class="anchor" id="line-4590"></span><span class="anchor" id="line-4591"></span><span class="anchor" id="line-4592"></span><span class="anchor" id="line-4593"></span><span class="anchor" id="line-4594"></span><span class="anchor" id="line-4595"></span><span class="anchor" id="line-4596"></span><span class="anchor" id="line-4597"></span><span class="anchor" id="line-4598"></span><span class="anchor" id="line-4599"></span><span class="anchor" id="line-4600"></span><span class="anchor" id="line-4601"></span><span class="anchor" id="line-4602"></span><span class="anchor" id="line-4603"></span><span class="anchor" id="line-4604"></span><span class="anchor" id="line-4605"></span><span class="anchor" id="line-4606"></span><span class="anchor" id="line-4607"></span><span class="anchor" id="line-4608"></span><span class="anchor" id="line-4609"></span><span class="anchor" id="line-4610"></span><span class="anchor" id="line-4611"></span><span class="anchor" id="line-4612"></span><span class="anchor" id="line-4613"></span><span class="anchor" id="line-4614"></span><span class="anchor" id="line-4615"></span><span class="anchor" id="line-4616"></span><span class="anchor" id="line-4617"></span><span class="anchor" id="line-4618"></span><span class="anchor" id="line-4619"></span><span class="anchor" id="line-4620"></span><span class="anchor" id="line-4621"></span><span class="anchor" id="line-4622"></span><span class="anchor" id="line-4623"></span><span class="anchor" id="line-4624"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-5d5e7fdaf3fc67c3080b9d3110897304d4c32446\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-5d5e7fdaf3fc67c3080b9d3110897304d4c32446', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-5d5e7fdaf3fc67c3080b9d3110897304d4c32446" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># interactivebutton.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ResWord">from</span> <span class="ID">wxPython</span><span class="Operator">.</span><span class="ID">lib</span><span class="Operator">.</span><span class="ID">buttons</span> <span class="ResWord">import</span> <span class="ID">wxGenButton</span></span>
<span class="line"><span class="LineNumber">   8 </span></span>
<span class="line"><span class="LineNumber">   9 </span><span class="ResWord">class</span> <span class="ID">MyPanel</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  10 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">ID</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  11 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">ID</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">DefaultPosition</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  12 </span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">btn</span> <span class="Operator">=</span> <span class="ID">wxGenButton</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">"button"</span><span class="Operator">,</span> <span class="ID">pos</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Point</span><span class="Operator">(</span><span class="Number">125</span><span class="Operator">,</span><span class="Number">100</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">=</span><span class="Operator">(</span><span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">btn</span><span class="Operator">.</span><span class="ID">SetBezelWidth</span><span class="Operator">(</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">btn</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_ENTER_WINDOW</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnEnterButton</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">btn</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_LEAVE_WINDOW</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnLeaveButton</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span></span>
<span class="line"><span class="LineNumber">  18 </span>    <span class="ResWord">def</span> <span class="ID">OnEnterButton</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  19 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">btn</span><span class="Operator">.</span><span class="ID">SetBackgroundColour</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Color</span><span class="Operator">(</span><span class="Number">128</span><span class="Operator">,</span> <span class="Number">128</span><span class="Operator">,</span><span class="Number">128</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  20 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">btn</span><span class="Operator">.</span><span class="ID">Refresh</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  21 </span></span>
<span class="line"><span class="LineNumber">  22 </span>    <span class="ResWord">def</span> <span class="ID">OnLeaveButton</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  23 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">btn</span><span class="Operator">.</span><span class="ID">SetBackgroundColour</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Color</span><span class="Operator">(</span><span class="Number">212</span><span class="Operator">,</span> <span class="Number">208</span><span class="Operator">,</span><span class="Number">200</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  24 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">btn</span><span class="Operator">.</span><span class="ID">Refresh</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  25 </span></span>
<span class="line"><span class="LineNumber">  26 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  27 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  28 </span>        <span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">"interactivebutton.py"</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">DefaultPosition</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Size</span><span class="Operator">(</span><span class="Number">350</span><span class="Operator">,</span><span class="Number">300</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  29 </span>        <span class="ID">mypanel</span> <span class="Operator">=</span> <span class="ID">MyPanel</span><span class="Operator">(</span><span class="ID">frame</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  30 </span>        <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  31 </span>        <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  32 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetTopWindow</span><span class="Operator">(</span><span class="ID">frame</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  33 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  34 </span></span>
<span class="line"><span class="LineNumber">  35 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  36 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-4625"></span><p class="line862">I have used<tt>wx.GenButton</tt> instead of basic <tt>wx.Button</tt>. <tt>wx.GenButton</tt> enables to change border settigs, which I find attractive. But <tt>wx.Button</tt> would work as well. <span class="anchor" id="line-4626"></span><span class="anchor" id="line-4627"></span></p><p class="line867">
</p><h3 id="Error_handling_without_dialogs">Error handling without dialogs</h3>
<span class="anchor" id="line-4628"></span><p class="line874">When an 
error occurs in an application, an error dialog usually appears. This 
might get annoying. I have noticed a better solution in SAP system. When
 a user enters an invalid command, statusbar turs red and an error 
message is displayed on stausbar. The red colour catches the eye and the
 user can easily read the error message. The following code mimics this 
situation. <span class="anchor" id="line-4629"></span><span class="anchor" id="line-4630"></span></p><p class="line867"><span class="anchor" id="line-4631"></span><span class="anchor" id="line-4632"></span><span class="anchor" id="line-4633"></span><span class="anchor" id="line-4634"></span><span class="anchor" id="line-4635"></span><span class="anchor" id="line-4636"></span><span class="anchor" id="line-4637"></span><span class="anchor" id="line-4638"></span><span class="anchor" id="line-4639"></span><span class="anchor" id="line-4640"></span><span class="anchor" id="line-4641"></span><span class="anchor" id="line-4642"></span><span class="anchor" id="line-4643"></span><span class="anchor" id="line-4644"></span><span class="anchor" id="line-4645"></span><span class="anchor" id="line-4646"></span><span class="anchor" id="line-4647"></span><span class="anchor" id="line-4648"></span><span class="anchor" id="line-4649"></span><span class="anchor" id="line-4650"></span><span class="anchor" id="line-4651"></span><span class="anchor" id="line-4652"></span><span class="anchor" id="line-4653"></span><span class="anchor" id="line-4654"></span><span class="anchor" id="line-4655"></span><span class="anchor" id="line-4656"></span><span class="anchor" id="line-4657"></span><span class="anchor" id="line-4658"></span><span class="anchor" id="line-4659"></span><span class="anchor" id="line-4660"></span><span class="anchor" id="line-4661"></span><span class="anchor" id="line-4662"></span><span class="anchor" id="line-4663"></span><span class="anchor" id="line-4664"></span><span class="anchor" id="line-4665"></span><span class="anchor" id="line-4666"></span><span class="anchor" id="line-4667"></span><span class="anchor" id="line-4668"></span><span class="anchor" id="line-4669"></span><span class="anchor" id="line-4670"></span><span class="anchor" id="line-4671"></span><span class="anchor" id="line-4672"></span><span class="anchor" id="line-4673"></span><span class="anchor" id="line-4674"></span><span class="anchor" id="line-4675"></span><span class="anchor" id="line-4676"></span><span class="anchor" id="line-4677"></span><span class="anchor" id="line-4678"></span><span class="anchor" id="line-4679"></span><span class="anchor" id="line-4680"></span><span class="anchor" id="line-4681"></span><span class="anchor" id="line-4682"></span><span class="anchor" id="line-4683"></span><span class="anchor" id="line-4684"></span><span class="anchor" id="line-4685"></span><span class="anchor" id="line-4686"></span><span class="anchor" id="line-4687"></span><span class="anchor" id="line-4688"></span><span class="anchor" id="line-4689"></span><span class="anchor" id="line-4690"></span><span class="anchor" id="line-4691"></span><span class="anchor" id="line-4692"></span><span class="anchor" id="line-4693"></span><span class="anchor" id="line-4694"></span><span class="anchor" id="line-4695"></span><span class="anchor" id="line-4696"></span><span class="anchor" id="line-4697"></span><span class="anchor" id="line-4698"></span><span class="anchor" id="line-4699"></span><span class="anchor" id="line-4700"></span><span class="anchor" id="line-4701"></span><span class="anchor" id="line-4702"></span><span class="anchor" id="line-4703"></span><span class="anchor" id="line-4704"></span><span class="anchor" id="line-4705"></span><span class="anchor" id="line-4706"></span><span class="anchor" id="line-4707"></span><span class="anchor" id="line-4708"></span><span class="anchor" id="line-4709"></span><span class="anchor" id="line-4710"></span><span class="anchor" id="line-4711"></span><span class="anchor" id="line-4712"></span><span class="anchor" id="line-4713"></span><span class="anchor" id="line-4714"></span><span class="anchor" id="line-4715"></span><span class="anchor" id="line-4716"></span><span class="anchor" id="line-4717"></span><span class="anchor" id="line-4718"></span><span class="anchor" id="line-4719"></span><span class="anchor" id="line-4720"></span><span class="anchor" id="line-4721"></span><span class="anchor" id="line-4722"></span><span class="anchor" id="line-4723"></span><span class="anchor" id="line-4724"></span><span class="anchor" id="line-4725"></span><span class="anchor" id="line-4726"></span><span class="anchor" id="line-4727"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-e1bdb475c54d9c78eac940a5a32a5adb9ef943b6\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-e1bdb475c54d9c78eac940a5a32a5adb9ef943b6', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-e1bdb475c54d9c78eac940a5a32a5adb9ef943b6" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># Isabelle</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ID">ID_TIMER</span> <span class="Operator">=</span> <span class="Number">1</span></span>
<span class="line"><span class="LineNumber">   8 </span><span class="ID">ID_EXIT</span>  <span class="Operator">=</span> <span class="Number">2</span></span>
<span class="line"><span class="LineNumber">   9 </span><span class="ID">ID_ABOUT</span> <span class="Operator">=</span> <span class="Number">3</span></span>
<span class="line"><span class="LineNumber">  10 </span><span class="ID">ID_BUTTON</span> <span class="Operator">=</span> <span class="Number">4</span></span>
<span class="line"><span class="LineNumber">  11 </span></span>
<span class="line"><span class="LineNumber">  12 </span><span class="ResWord">class</span> <span class="ID">Isabelle</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  13 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span></span>
<span class="line"><span class="LineNumber">  16 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">timer</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Timer</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">ID_TIMER</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">blick</span> <span class="Operator">=</span> <span class="Number">0</span></span>
<span class="line"><span class="LineNumber">  18 </span></span>
<span class="line"><span class="LineNumber">  19 </span>        <span class="ID">file</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Menu</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  20 </span>        <span class="ID">file</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="ID">ID_EXIT</span><span class="Operator">,</span> <span class="String">'&amp;Quit\tCtrl+Q'</span><span class="Operator">,</span> <span class="String">'Quit Isabelle'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  21 </span></span>
<span class="line"><span class="LineNumber">  22 </span>        <span class="ID">help</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Menu</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  23 </span>        <span class="ID">help</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="ID">ID_ABOUT</span><span class="Operator">,</span> <span class="String">'&amp;About'</span><span class="Operator">,</span> <span class="String">'O Programe'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  24 </span></span>
<span class="line"><span class="LineNumber">  25 </span></span>
<span class="line"><span class="LineNumber">  26 </span>        <span class="ID">menubar</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MenuBar</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  27 </span>        <span class="ID">menubar</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="ID">file</span><span class="Operator">,</span> <span class="String">'&amp;File'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  28 </span>        <span class="ID">menubar</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="ID">help</span><span class="Operator">,</span> <span class="String">'&amp;Help'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  29 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetMenuBar</span><span class="Operator">(</span><span class="ID">menubar</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  30 </span></span>
<span class="line"><span class="LineNumber">  31 </span>        <span class="ID">toolbar</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ToolBar</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  32 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tc</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TextCtrl</span><span class="Operator">(</span><span class="ID">toolbar</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">100</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  33 </span>        <span class="ID">btn</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">toolbar</span><span class="Operator">,</span> <span class="ID">ID_BUTTON</span><span class="Operator">,</span> <span class="String">'Ok'</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">40</span><span class="Operator">,</span> <span class="Number">28</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  34 </span></span>
<span class="line"><span class="LineNumber">  35 </span>        <span class="ID">toolbar</span><span class="Operator">.</span><span class="ID">AddControl</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">tc</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  36 </span>        <span class="ID">toolbar</span><span class="Operator">.</span><span class="ID">AddSeparator</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  37 </span>        <span class="ID">toolbar</span><span class="Operator">.</span><span class="ID">AddControl</span><span class="Operator">(</span><span class="ID">btn</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  38 </span>        <span class="ID">toolbar</span><span class="Operator">.</span><span class="ID">Realize</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  39 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetToolBar</span><span class="Operator">(</span><span class="ID">toolbar</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  40 </span></span>
<span class="line"><span class="LineNumber">  41 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnLaunchCommandOk</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="ID">ID_BUTTON</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  42 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_MENU</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnAbout</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="ID">ID_ABOUT</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  43 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_MENU</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnExit</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="ID">ID_EXIT</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  44 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_TIMER</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnTimer</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="ID">ID_TIMER</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  45 </span></span>
<span class="line"><span class="LineNumber">  46 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">panel</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">0</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">500</span> <span class="Operator">,</span> <span class="Number">300</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  47 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">panel</span><span class="Operator">.</span><span class="ID">SetBackgroundColour</span><span class="Operator">(</span><span class="String">'GRAY'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  48 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">sizer</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">BoxSizer</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">VERTICAL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  49 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">sizer</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">panel</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  50 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetSizer</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">sizer</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  51 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">statusbar</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">CreateStatusBar</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  52 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">statusbar</span><span class="Operator">.</span><span class="ID">SetStatusText</span><span class="Operator">(</span><span class="String">'Welcome to Isabelle'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  53 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  54 </span></span>
<span class="line"><span class="LineNumber">  55 </span>    <span class="ResWord">def</span> <span class="ID">OnExit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  56 </span>        <span class="ID">dlg</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MessageDialog</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="String">'Are you sure to quit Isabelle?'</span><span class="Operator">,</span> <span class="String">'Please Confirm'</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">YES_NO</span> <span class="Operator">|</span></span>
<span class="line"><span class="LineNumber">  57 </span>                <span class="ID">wx</span><span class="Operator">.</span><span class="ID">NO_DEFAULT</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ICON_QUESTION</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  58 </span>        <span class="ResWord">if</span> <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">ShowModal</span><span class="Operator">(</span><span class="Operator">)</span> <span class="Operator">==</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ID_YES</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  59 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">Close</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  60 </span></span>
<span class="line"><span class="LineNumber">  61 </span></span>
<span class="line"><span class="LineNumber">  62 </span>    <span class="ResWord">def</span> <span class="ID">OnAbout</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  63 </span>        <span class="ID">dlg</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MessageDialog</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="String">'Isabelle\t\n'</span> <span class="String">'2004\t'</span><span class="Operator">,</span> <span class="String">'About'</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  64 </span>                 <span class="ID">wx</span><span class="Operator">.</span><span class="ID">OK</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ICON_INFORMATION</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  65 </span>        <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">ShowModal</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  66 </span>        <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">Destroy</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  67 </span></span>
<span class="line"><span class="LineNumber">  68 </span></span>
<span class="line"><span class="LineNumber">  69 </span>    <span class="ResWord">def</span> <span class="ID">OnLaunchCommandOk</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  70 </span>        <span class="ID">input</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tc</span><span class="Operator">.</span><span class="ID">GetValue</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  71 </span>        <span class="ResWord">if</span> <span class="ID">input</span> <span class="Operator">==</span> <span class="String">'/bye'</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  72 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnExit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  73 </span>        <span class="ResWord">elif</span> <span class="ID">input</span> <span class="Operator">==</span> <span class="String">'/about'</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  74 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnAbout</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  75 </span>        <span class="ResWord">elif</span> <span class="ID">input</span> <span class="Operator">==</span> <span class="String">'/bell'</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  76 </span>            <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bell</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  77 </span>        <span class="ResWord">else</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  78 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">statusbar</span><span class="Operator">.</span><span class="ID">SetBackgroundColour</span><span class="Operator">(</span><span class="String">'RED'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  79 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">statusbar</span><span class="Operator">.</span><span class="ID">SetStatusText</span><span class="Operator">(</span><span class="String">'Unknown Command'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  80 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">statusbar</span><span class="Operator">.</span><span class="ID">Refresh</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  81 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">timer</span><span class="Operator">.</span><span class="ID">Start</span><span class="Operator">(</span><span class="Number">50</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  82 </span></span>
<span class="line"><span class="LineNumber">  83 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tc</span><span class="Operator">.</span><span class="ID">Clear</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  84 </span></span>
<span class="line"><span class="LineNumber">  85 </span>    <span class="ResWord">def</span> <span class="ID">OnTimer</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  86 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">blick</span> <span class="Operator">+=</span> <span class="Number">1</span></span>
<span class="line"><span class="LineNumber">  87 </span>        <span class="ResWord">if</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">blick</span> <span class="Operator">==</span> <span class="Number">25</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  88 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">statusbar</span><span class="Operator">.</span><span class="ID">SetBackgroundColour</span><span class="Operator">(</span><span class="String">'#E0E2EB'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  89 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">statusbar</span><span class="Operator">.</span><span class="ID">Refresh</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  90 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">timer</span><span class="Operator">.</span><span class="ID">Stop</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  91 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">blick</span> <span class="Operator">=</span> <span class="Number">0</span></span>
<span class="line"><span class="LineNumber">  92 </span></span>
<span class="line"><span class="LineNumber">  93 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  94 </span><span class="ID">Isabelle</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Isabelle'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  95 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-4728"></span><p class="line862">There is a<tt>wx.TextCtrl</tt>
 on the Statusbar. There you enter your commands. We have defined three 
commands. /bye, /about and /beep.  If you mistype any of them, Statusbar
 turns red and displays an error. This is done with the <tt>wx.Timer</tt> class. Firstly, you need to create a <tt>wx.Timer</tt> object. <span class="anchor" id="line-4729"></span><span class="anchor" id="line-4730"></span></p><p class="line867"><span class="anchor" id="line-4731"></span><span class="anchor" id="line-4732"></span></p><pre>self.timer = wx.Timer(self, 1)</pre><span class="anchor" id="line-4733"></span><p class="line862">Then you bind this newly created object to a specific method -- in our case<tt>OnTimer</tt>. <span class="anchor" id="line-4734"></span><span class="anchor" id="line-4735"></span></p><p class="line867"><span class="anchor" id="line-4736"></span><span class="anchor" id="line-4737"></span></p><pre>wx.EVT_TIMER(self,  1, self.OnTimer)</pre><span class="anchor" id="line-4738"></span><p class="line874">When the user enters an invalid command, the timer object is started with the following code. <span class="anchor" id="line-4739"></span><span class="anchor" id="line-4740"></span></p><p class="line867"><span class="anchor" id="line-4741"></span><span class="anchor" id="line-4742"></span></p><pre>self.timer.Start(10)</pre><span class="anchor" id="line-4743"></span><p class="line862">Every 10 milliseconds<tt>OnTimer</tt> method is called. If variable self.blick equals 25, we stop the timer with <span class="anchor" id="line-4744"></span><span class="anchor" id="line-4745"></span></p><p class="line867"><span class="anchor" id="line-4746"></span><span class="anchor" id="line-4747"></span></p><pre>self.timer.Stop()</pre><span class="anchor" id="line-4748"></span><p class="line867"><img alt="isabelle.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_033.png" title="isabelle.png"> <span class="anchor" id="line-4749"></span><span class="anchor" id="line-4750"></span></p><p class="line867"><strong>Figure: isabelle.py</strong> <span class="anchor" id="line-4751"></span><span class="anchor" id="line-4752"></span></p><p class="line867">
</p><h3 id="UndoRedoFramework">UndoRedoFramework</h3>
<span class="anchor" id="line-4753"></span><p class="line874">Many 
applications have the ability to undo and redo the user's actions. The 
following example shows how it can be accomplished in wxPython. <span class="anchor" id="line-4754"></span><span class="anchor" id="line-4755"></span></p><p class="line867"><span class="anchor" id="line-4756"></span><span class="anchor" id="line-4757"></span><span class="anchor" id="line-4758"></span><span class="anchor" id="line-4759"></span><span class="anchor" id="line-4760"></span><span class="anchor" id="line-4761"></span><span class="anchor" id="line-4762"></span><span class="anchor" id="line-4763"></span><span class="anchor" id="line-4764"></span><span class="anchor" id="line-4765"></span><span class="anchor" id="line-4766"></span><span class="anchor" id="line-4767"></span><span class="anchor" id="line-4768"></span><span class="anchor" id="line-4769"></span><span class="anchor" id="line-4770"></span><span class="anchor" id="line-4771"></span><span class="anchor" id="line-4772"></span><span class="anchor" id="line-4773"></span><span class="anchor" id="line-4774"></span><span class="anchor" id="line-4775"></span><span class="anchor" id="line-4776"></span><span class="anchor" id="line-4777"></span><span class="anchor" id="line-4778"></span><span class="anchor" id="line-4779"></span><span class="anchor" id="line-4780"></span><span class="anchor" id="line-4781"></span><span class="anchor" id="line-4782"></span><span class="anchor" id="line-4783"></span><span class="anchor" id="line-4784"></span><span class="anchor" id="line-4785"></span><span class="anchor" id="line-4786"></span><span class="anchor" id="line-4787"></span><span class="anchor" id="line-4788"></span><span class="anchor" id="line-4789"></span><span class="anchor" id="line-4790"></span><span class="anchor" id="line-4791"></span><span class="anchor" id="line-4792"></span><span class="anchor" id="line-4793"></span><span class="anchor" id="line-4794"></span><span class="anchor" id="line-4795"></span><span class="anchor" id="line-4796"></span><span class="anchor" id="line-4797"></span><span class="anchor" id="line-4798"></span><span class="anchor" id="line-4799"></span><span class="anchor" id="line-4800"></span><span class="anchor" id="line-4801"></span><span class="anchor" id="line-4802"></span><span class="anchor" id="line-4803"></span><span class="anchor" id="line-4804"></span><span class="anchor" id="line-4805"></span><span class="anchor" id="line-4806"></span><span class="anchor" id="line-4807"></span><span class="anchor" id="line-4808"></span><span class="anchor" id="line-4809"></span><span class="anchor" id="line-4810"></span><span class="anchor" id="line-4811"></span><span class="anchor" id="line-4812"></span><span class="anchor" id="line-4813"></span><span class="anchor" id="line-4814"></span><span class="anchor" id="line-4815"></span><span class="anchor" id="line-4816"></span><span class="anchor" id="line-4817"></span><span class="anchor" id="line-4818"></span><span class="anchor" id="line-4819"></span><span class="anchor" id="line-4820"></span><span class="anchor" id="line-4821"></span><span class="anchor" id="line-4822"></span><span class="anchor" id="line-4823"></span><span class="anchor" id="line-4824"></span><span class="anchor" id="line-4825"></span><span class="anchor" id="line-4826"></span><span class="anchor" id="line-4827"></span><span class="anchor" id="line-4828"></span><span class="anchor" id="line-4829"></span><span class="anchor" id="line-4830"></span><span class="anchor" id="line-4831"></span><span class="anchor" id="line-4832"></span><span class="anchor" id="line-4833"></span><span class="anchor" id="line-4834"></span><span class="anchor" id="line-4835"></span><span class="anchor" id="line-4836"></span><span class="anchor" id="line-4837"></span><span class="anchor" id="line-4838"></span><span class="anchor" id="line-4839"></span><span class="anchor" id="line-4840"></span><span class="anchor" id="line-4841"></span><span class="anchor" id="line-4842"></span><span class="anchor" id="line-4843"></span><span class="anchor" id="line-4844"></span><span class="anchor" id="line-4845"></span><span class="anchor" id="line-4846"></span><span class="anchor" id="line-4847"></span><span class="anchor" id="line-4848"></span><span class="anchor" id="line-4849"></span><span class="anchor" id="line-4850"></span><span class="anchor" id="line-4851"></span><span class="anchor" id="line-4852"></span><span class="anchor" id="line-4853"></span><span class="anchor" id="line-4854"></span><span class="anchor" id="line-4855"></span><span class="anchor" id="line-4856"></span><span class="anchor" id="line-4857"></span><span class="anchor" id="line-4858"></span><span class="anchor" id="line-4859"></span><span class="anchor" id="line-4860"></span><span class="anchor" id="line-4861"></span><span class="anchor" id="line-4862"></span><span class="anchor" id="line-4863"></span><span class="anchor" id="line-4864"></span><span class="anchor" id="line-4865"></span><span class="anchor" id="line-4866"></span><span class="anchor" id="line-4867"></span><span class="anchor" id="line-4868"></span><span class="anchor" id="line-4869"></span><span class="anchor" id="line-4870"></span><span class="anchor" id="line-4871"></span><span class="anchor" id="line-4872"></span><span class="anchor" id="line-4873"></span><span class="anchor" id="line-4874"></span><span class="anchor" id="line-4875"></span><span class="anchor" id="line-4876"></span><span class="anchor" id="line-4877"></span><span class="anchor" id="line-4878"></span><span class="anchor" id="line-4879"></span><span class="anchor" id="line-4880"></span><span class="anchor" id="line-4881"></span><span class="anchor" id="line-4882"></span><span class="anchor" id="line-4883"></span><span class="anchor" id="line-4884"></span><span class="anchor" id="line-4885"></span><span class="anchor" id="line-4886"></span><span class="anchor" id="line-4887"></span><span class="anchor" id="line-4888"></span><span class="anchor" id="line-4889"></span><span class="anchor" id="line-4890"></span><span class="anchor" id="line-4891"></span><span class="anchor" id="line-4892"></span><span class="anchor" id="line-4893"></span><span class="anchor" id="line-4894"></span><span class="anchor" id="line-4895"></span><span class="anchor" id="line-4896"></span><span class="anchor" id="line-4897"></span><span class="anchor" id="line-4898"></span><span class="anchor" id="line-4899"></span><span class="anchor" id="line-4900"></span><span class="anchor" id="line-4901"></span><span class="anchor" id="line-4902"></span><span class="anchor" id="line-4903"></span><span class="anchor" id="line-4904"></span><span class="anchor" id="line-4905"></span><span class="anchor" id="line-4906"></span><span class="anchor" id="line-4907"></span><span class="anchor" id="line-4908"></span><span class="anchor" id="line-4909"></span><span class="anchor" id="line-4910"></span><span class="anchor" id="line-4911"></span><span class="anchor" id="line-4912"></span><span class="anchor" id="line-4913"></span><span class="anchor" id="line-4914"></span><span class="anchor" id="line-4915"></span><span class="anchor" id="line-4916"></span><span class="anchor" id="line-4917"></span><span class="anchor" id="line-4918"></span><span class="anchor" id="line-4919"></span><span class="anchor" id="line-4920"></span><span class="anchor" id="line-4921"></span><span class="anchor" id="line-4922"></span><span class="anchor" id="line-4923"></span><span class="anchor" id="line-4924"></span><span class="anchor" id="line-4925"></span><span class="anchor" id="line-4926"></span><span class="anchor" id="line-4927"></span><span class="anchor" id="line-4928"></span><span class="anchor" id="line-4929"></span><span class="anchor" id="line-4930"></span><span class="anchor" id="line-4931"></span><span class="anchor" id="line-4932"></span><span class="anchor" id="line-4933"></span><span class="anchor" id="line-4934"></span><span class="anchor" id="line-4935"></span><span class="anchor" id="line-4936"></span><span class="anchor" id="line-4937"></span><span class="anchor" id="line-4938"></span><span class="anchor" id="line-4939"></span><span class="anchor" id="line-4940"></span><span class="anchor" id="line-4941"></span><span class="anchor" id="line-4942"></span><span class="anchor" id="line-4943"></span><span class="anchor" id="line-4944"></span><span class="anchor" id="line-4945"></span><span class="anchor" id="line-4946"></span><span class="anchor" id="line-4947"></span><span class="anchor" id="line-4948"></span><span class="anchor" id="line-4949"></span><span class="anchor" id="line-4950"></span><span class="anchor" id="line-4951"></span><span class="anchor" id="line-4952"></span><span class="anchor" id="line-4953"></span><span class="anchor" id="line-4954"></span><span class="anchor" id="line-4955"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-1466cfc3823b75e60d13222fdd97472c520ca7f4\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-1466cfc3823b75e60d13222fdd97472c520ca7f4', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-1466cfc3823b75e60d13222fdd97472c520ca7f4" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># newt.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">from</span> <span class="ID">wxPython</span><span class="Operator">.</span><span class="ID">lib</span><span class="Operator">.</span><span class="ID">sheet</span> <span class="ResWord">import</span> <span class="Operator">*</span></span>
<span class="line"><span class="LineNumber">   6 </span><span class="ResWord">from</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">lib</span><span class="Operator">.</span><span class="ID">plot</span> <span class="ResWord">import</span> <span class="Operator">*</span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   8 </span></span>
<span class="line"><span class="LineNumber">   9 </span><span class="ID">stockUndo</span> <span class="Operator">=</span> <span class="Operator">[</span><span class="Operator">]</span></span>
<span class="line"><span class="LineNumber">  10 </span><span class="ID">stockRedo</span> <span class="Operator">=</span> <span class="Operator">[</span><span class="Operator">]</span></span>
<span class="line"><span class="LineNumber">  11 </span></span>
<span class="line"><span class="LineNumber">  12 </span><span class="ResWord">class</span> <span class="ID">UndoText</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  13 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">sheet</span><span class="Operator">,</span> <span class="ID">text1</span><span class="Operator">,</span> <span class="ID">text2</span><span class="Operator">,</span> <span class="ID">row</span><span class="Operator">,</span> <span class="ID">column</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">RedoText</span> <span class="Operator">=</span>  <span class="ID">text2</span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">row</span> <span class="Operator">=</span> <span class="ID">row</span></span>
<span class="line"><span class="LineNumber">  16 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">col</span> <span class="Operator">=</span> <span class="ID">column</span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">UndoText</span> <span class="Operator">=</span> <span class="ID">text1</span></span>
<span class="line"><span class="LineNumber">  18 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">sheet</span> <span class="Operator">=</span> <span class="ID">sheet</span></span>
<span class="line"><span class="LineNumber">  19 </span></span>
<span class="line"><span class="LineNumber">  20 </span>    <span class="ResWord">def</span> <span class="ID">undo</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  21 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">RedoText</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">sheet</span><span class="Operator">.</span><span class="ID">GetCellValue</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">row</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">col</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  22 </span>        <span class="ResWord">if</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">UndoText</span> <span class="Operator">==</span>  <span class="ID">None</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  23 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">sheetSetCellValue</span><span class="Operator">(</span><span class="String">''</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  24 </span>        <span class="ResWord">else</span><span class="Operator">:</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">sheet</span><span class="Operator">.</span><span class="ID">SetCellValue</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">row</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">col</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">UndoText</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  25 </span></span>
<span class="line"><span class="LineNumber">  26 </span>    <span class="ResWord">def</span> <span class="ID">redo</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  27 </span>        <span class="ResWord">if</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">RedoText</span> <span class="Operator">==</span> <span class="ID">None</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  28 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">sheet</span><span class="Operator">.</span><span class="ID">SetCellValue</span><span class="Operator">(</span><span class="String">''</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  29 </span>        <span class="ResWord">else</span><span class="Operator">:</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">sheet</span><span class="Operator">.</span><span class="ID">SetCellValue</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">row</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">col</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">RedoText</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  30 </span></span>
<span class="line"><span class="LineNumber">  31 </span><span class="ResWord">class</span> <span class="ID">UndoColSize</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  32 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">sheet</span><span class="Operator">,</span> <span class="ID">position</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  33 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">sheet</span> <span class="Operator">=</span> <span class="ID">sheet</span></span>
<span class="line"><span class="LineNumber">  34 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">pos</span> <span class="Operator">=</span> <span class="ID">position</span></span>
<span class="line"><span class="LineNumber">  35 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">RedoSize</span> <span class="Operator">=</span> <span class="ID">size</span></span>
<span class="line"><span class="LineNumber">  36 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">UndoSize</span> <span class="Operator">=</span> <span class="Number">80</span></span>
<span class="line"><span class="LineNumber">  37 </span></span>
<span class="line"><span class="LineNumber">  38 </span>    <span class="ResWord">def</span> <span class="ID">undo</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  39 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">RedoSize</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">sheet</span><span class="Operator">.</span><span class="ID">GetColSize</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">pos</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  40 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">sheet</span><span class="Operator">.</span><span class="ID">SetColSize</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">pos</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">UndoSize</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  41 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">sheet</span><span class="Operator">.</span><span class="ID">ForceRefresh</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  42 </span></span>
<span class="line"><span class="LineNumber">  43 </span>    <span class="ResWord">def</span> <span class="ID">redo</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  44 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">UndoSize</span> <span class="Operator">=</span> <span class="Number">80</span></span>
<span class="line"><span class="LineNumber">  45 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">sheet</span><span class="Operator">.</span><span class="ID">SetColSize</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">pos</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">RedoSize</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  46 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">sheet</span><span class="Operator">.</span><span class="ID">ForceRefresh</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  47 </span></span>
<span class="line"><span class="LineNumber">  48 </span><span class="ResWord">class</span> <span class="ID">UndoRowSize</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  49 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">sheet</span><span class="Operator">,</span> <span class="ID">position</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  50 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">sheet</span> <span class="Operator">=</span> <span class="ID">sheet</span></span>
<span class="line"><span class="LineNumber">  51 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">pos</span> <span class="Operator">=</span> <span class="ID">position</span></span>
<span class="line"><span class="LineNumber">  52 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">RedoSize</span> <span class="Operator">=</span> <span class="ID">size</span></span>
<span class="line"><span class="LineNumber">  53 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">UndoSize</span> <span class="Operator">=</span> <span class="Number">20</span></span>
<span class="line"><span class="LineNumber">  54 </span></span>
<span class="line"><span class="LineNumber">  55 </span>    <span class="ResWord">def</span> <span class="ID">undo</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  56 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">RedoSize</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">sheet</span><span class="Operator">.</span><span class="ID">GetRowSize</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">pos</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  57 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">sheet</span><span class="Operator">.</span><span class="ID">SetRowSize</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">pos</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">UndoSize</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  58 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">sheet</span><span class="Operator">.</span><span class="ID">ForceRefresh</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  59 </span></span>
<span class="line"><span class="LineNumber">  60 </span>    <span class="ResWord">def</span> <span class="ID">redo</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  61 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">UndoSize</span> <span class="Operator">=</span> <span class="Number">20</span></span>
<span class="line"><span class="LineNumber">  62 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">sheet</span><span class="Operator">.</span><span class="ID">SetRowSize</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">pos</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">RedoSize</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  63 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">sheet</span><span class="Operator">.</span><span class="ID">ForceRefresh</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  64 </span></span>
<span class="line"><span class="LineNumber">  65 </span><span class="ResWord">class</span> <span class="ID">MySheet</span><span class="Operator">(</span><span class="ID">CSheet</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  66 </span>    <span class="ID">instance</span> <span class="Operator">=</span> <span class="Number">0</span></span>
<span class="line"><span class="LineNumber">  67 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  68 </span>        <span class="ID">CSheet</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  69 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetLabelBackgroundColour</span><span class="Operator">(</span><span class="String">'#DBD4D4'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  70 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetRowLabelAlignment</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_CENTRE</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_CENTRE</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  71 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">text</span> <span class="Operator">=</span> <span class="String">''</span></span>
<span class="line"><span class="LineNumber">  72 </span></span>
<span class="line"><span class="LineNumber">  73 </span>    <span class="ResWord">def</span> <span class="ID">OnCellChange</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  74 </span>        <span class="ID">toolbar</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">GetParent</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">.</span><span class="ID">toolbar1</span></span>
<span class="line"><span class="LineNumber">  75 </span>        <span class="ResWord">if</span> <span class="ResWord">not</span> <span class="ID">toolbar</span><span class="Operator">.</span><span class="ID">GetToolEnabled</span><span class="Operator">(</span><span class="Number">808</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  76 </span>                <span class="ID">toolbar</span><span class="Operator">.</span><span class="ID">EnableTool</span><span class="Operator">(</span><span class="Number">808</span><span class="Operator">,</span> <span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  77 </span>        <span class="ID">r</span> <span class="Operator">=</span> <span class="ID">event</span><span class="Operator">.</span><span class="ID">GetRow</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  78 </span>        <span class="ID">c</span> <span class="Operator">=</span> <span class="ID">event</span><span class="Operator">.</span><span class="ID">GetCol</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  79 </span>        <span class="ID">text</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">GetCellValue</span><span class="Operator">(</span><span class="ID">r</span><span class="Operator">,</span> <span class="ID">c</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  80 </span>        <span class="Comment"># self.text - text before change</span></span>
<span class="line"><span class="LineNumber">  81 </span><span class="Comment"></span>        <span class="Comment"># text - text after change</span></span>
<span class="line"><span class="LineNumber">  82 </span><span class="Comment"></span>        <span class="ID">undo</span> <span class="Operator">=</span> <span class="ID">UndoText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">text</span><span class="Operator">,</span> <span class="ID">text</span><span class="Operator">,</span> <span class="ID">r</span><span class="Operator">,</span> <span class="ID">c</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  83 </span>        <span class="ID">stockUndo</span><span class="Operator">.</span><span class="ID">append</span><span class="Operator">(</span><span class="ID">undo</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  84 </span></span>
<span class="line"><span class="LineNumber">  85 </span>        <span class="ResWord">if</span> <span class="ID">stockRedo</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  86 </span>            <span class="Comment"># this might be surprising, but it is a standard behaviour</span></span>
<span class="line"><span class="LineNumber">  87 </span><span class="Comment"></span>            <span class="Comment"># in all spreadsheets</span></span>
<span class="line"><span class="LineNumber">  88 </span><span class="Comment"></span>            <span class="ResWord">del</span> <span class="ID">stockRedo</span><span class="Operator">[</span><span class="Operator">:</span><span class="Operator">]</span></span>
<span class="line"><span class="LineNumber">  89 </span>            <span class="ID">toolbar</span><span class="Operator">.</span><span class="ID">EnableTool</span><span class="Operator">(</span><span class="Number">809</span><span class="Operator">,</span> <span class="ID">False</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  90 </span></span>
<span class="line"><span class="LineNumber">  91 </span>    <span class="ResWord">def</span> <span class="ID">OnColSize</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  92 </span>        <span class="ID">toolbar</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">GetParent</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">.</span><span class="ID">toolbar1</span></span>
<span class="line"><span class="LineNumber">  93 </span></span>
<span class="line"><span class="LineNumber">  94 </span>        <span class="ResWord">if</span> <span class="ResWord">not</span> <span class="ID">toolbar</span><span class="Operator">.</span><span class="ID">GetToolEnabled</span><span class="Operator">(</span><span class="Number">808</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  95 </span>                <span class="ID">toolbar</span><span class="Operator">.</span><span class="ID">EnableTool</span><span class="Operator">(</span><span class="Number">808</span><span class="Operator">,</span> <span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  96 </span></span>
<span class="line"><span class="LineNumber">  97 </span>        <span class="ID">pos</span> <span class="Operator">=</span>  <span class="ID">event</span><span class="Operator">.</span><span class="ID">GetRowOrCol</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  98 </span>        <span class="ID">size</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">GetColSize</span><span class="Operator">(</span><span class="ID">pos</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  99 </span>        <span class="ID">undo</span> <span class="Operator">=</span> <span class="ID">UndoColSize</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">pos</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 100 </span>        <span class="ID">stockUndo</span><span class="Operator">.</span><span class="ID">append</span><span class="Operator">(</span><span class="ID">undo</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 101 </span></span>
<span class="line"><span class="LineNumber"> 102 </span>        <span class="ResWord">if</span> <span class="ID">stockRedo</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 103 </span>            <span class="ResWord">del</span> <span class="ID">stockRedo</span><span class="Operator">[</span><span class="Operator">:</span><span class="Operator">]</span></span>
<span class="line"><span class="LineNumber"> 104 </span>            <span class="ID">toolbar</span><span class="Operator">.</span><span class="ID">EnableTool</span><span class="Operator">(</span><span class="Number">809</span><span class="Operator">,</span> <span class="ID">False</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 105 </span></span>
<span class="line"><span class="LineNumber"> 106 </span>    <span class="ResWord">def</span> <span class="ID">OnRowSize</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 107 </span>        <span class="ID">toolbar</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">GetParent</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">.</span><span class="ID">toolbar1</span></span>
<span class="line"><span class="LineNumber"> 108 </span>        <span class="ResWord">if</span> <span class="ResWord">not</span> <span class="ID">toolbar</span><span class="Operator">.</span><span class="ID">GetToolEnabled</span><span class="Operator">(</span><span class="Number">808</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 109 </span>                <span class="ID">toolbar</span><span class="Operator">.</span><span class="ID">EnableTool</span><span class="Operator">(</span><span class="Number">808</span><span class="Operator">,</span> <span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 110 </span></span>
<span class="line"><span class="LineNumber"> 111 </span>        <span class="ID">pos</span> <span class="Operator">=</span>  <span class="ID">event</span><span class="Operator">.</span><span class="ID">GetRowOrCol</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 112 </span>        <span class="ID">size</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">GetRowSize</span><span class="Operator">(</span><span class="ID">pos</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 113 </span>        <span class="ID">undo</span> <span class="Operator">=</span> <span class="ID">UndoRowSize</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">pos</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 114 </span></span>
<span class="line"><span class="LineNumber"> 115 </span>        <span class="ID">stockUndo</span><span class="Operator">.</span><span class="ID">append</span><span class="Operator">(</span><span class="ID">undo</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 116 </span>        <span class="ResWord">if</span> <span class="ID">stockRedo</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 117 </span>            <span class="ResWord">del</span> <span class="ID">stockRedo</span><span class="Operator">[</span><span class="Operator">:</span><span class="Operator">]</span></span>
<span class="line"><span class="LineNumber"> 118 </span>            <span class="ID">toolbar</span><span class="Operator">.</span><span class="ID">EnableTool</span><span class="Operator">(</span><span class="Number">809</span><span class="Operator">,</span> <span class="ID">False</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 119 </span></span>
<span class="line"><span class="LineNumber"> 120 </span><span class="ResWord">class</span> <span class="ID">Newt</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 121 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span><span class="ID">parent</span><span class="Operator">,</span><span class="ID">id</span><span class="Operator">,</span><span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 122 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span><span class="ID">parent</span><span class="Operator">,</span><span class="Operator">-</span><span class="Number">4</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">size</span> <span class="Operator">=</span> <span class="Operator">(</span> <span class="Number">550</span><span class="Operator">,</span> <span class="Number">500</span><span class="Operator">)</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 123 </span>                         <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">DEFAULT_FRAME_STYLE</span><span class="Operator">|</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">NO_FULL_REPAINT_ON_RESIZE</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 124 </span></span>
<span class="line"><span class="LineNumber"> 125 </span>        <span class="ID">box</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BoxSizer</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">VERTICAL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 126 </span>        <span class="ID">menuBar</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MenuBar</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 127 </span>        <span class="ID">menu1</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Menu</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 128 </span>        <span class="ID">quit</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MenuItem</span><span class="Operator">(</span><span class="ID">menu1</span><span class="Operator">,</span> <span class="Number">105</span><span class="Operator">,</span> <span class="String">"&amp;Quit\tCtrl+Q"</span><span class="Operator">,</span> <span class="String">"Quits Newt"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 129 </span>        <span class="ID">quit</span><span class="Operator">.</span><span class="ID">SetBitmap</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Image</span><span class="Operator">(</span><span class="String">'stock_exit-16.png'</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 130 </span>                               <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BITMAP_TYPE_PNG</span><span class="Operator">)</span><span class="Operator">.</span><span class="ID">ConvertToBitmap</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 131 </span>        <span class="ID">menu1</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">quit</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 132 </span>        <span class="ID">menuBar</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="ID">menu1</span><span class="Operator">,</span> <span class="String">"&amp;File"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 133 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_MENU</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnQuitNewt</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">105</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 134 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetMenuBar</span><span class="Operator">(</span><span class="ID">menuBar</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 135 </span>        <span class="Comment"># Setting up Toolbar</span></span>
<span class="line"><span class="LineNumber"> 136 </span><span class="Comment"></span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">toolbar1</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ToolBar</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">TB_HORIZONTAL</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">NO_BORDER</span> <span class="Operator">|</span></span>
<span class="line"><span class="LineNumber"> 137 </span>                                        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TB_FLAT</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TB_TEXT</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 138 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">toolbar1</span><span class="Operator">.</span><span class="ID">AddSimpleTool</span><span class="Operator">(</span><span class="Number">808</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 139 </span>              <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Image</span><span class="Operator">(</span><span class="String">'stock_undo.png'</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BITMAP_TYPE_PNG</span><span class="Operator">)</span><span class="Operator">.</span><span class="ID">ConvertToBitmap</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 140 </span>              <span class="String">'Undo'</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 141 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">toolbar1</span><span class="Operator">.</span><span class="ID">AddSimpleTool</span><span class="Operator">(</span><span class="Number">809</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 142 </span>              <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Image</span><span class="Operator">(</span><span class="String">'stock_redo.png'</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BITMAP_TYPE_PNG</span><span class="Operator">)</span><span class="Operator">.</span><span class="ID">ConvertToBitmap</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 143 </span>              <span class="String">'Redo'</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 144 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">toolbar1</span><span class="Operator">.</span><span class="ID">EnableTool</span><span class="Operator">(</span><span class="Number">808</span><span class="Operator">,</span> <span class="ID">False</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 145 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">toolbar1</span><span class="Operator">.</span><span class="ID">EnableTool</span><span class="Operator">(</span><span class="Number">809</span><span class="Operator">,</span> <span class="ID">False</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 146 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">toolbar1</span><span class="Operator">.</span><span class="ID">AddSeparator</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 147 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">toolbar1</span><span class="Operator">.</span><span class="ID">AddSimpleTool</span><span class="Operator">(</span><span class="Number">813</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 148 </span>              <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Image</span><span class="Operator">(</span><span class="String">'stock_exit.png'</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BITMAP_TYPE_PNG</span><span class="Operator">)</span><span class="Operator">.</span><span class="ID">ConvertToBitmap</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 149 </span>              <span class="String">'Quit'</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 150 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">toolbar1</span><span class="Operator">.</span><span class="ID">Realize</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 151 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">toolbar1</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_TOOL</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnUndo</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">808</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 152 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">toolbar1</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_TOOL</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnRedo</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">809</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 153 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">toolbar1</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_TOOL</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnQuitNewt</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">813</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 154 </span>        <span class="ID">box</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">toolbar1</span><span class="Operator">,</span> <span class="ID">border</span><span class="Operator">=</span><span class="Number">5</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 155 </span>        <span class="ID">box</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="Operator">(</span><span class="Number">5</span><span class="Operator">,</span><span class="Number">10</span><span class="Operator">)</span><span class="Operator">,</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 156 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetSizer</span><span class="Operator">(</span><span class="ID">box</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 157 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">sheet1</span> <span class="Operator">=</span> <span class="ID">MySheet</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 158 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">sheet1</span><span class="Operator">.</span><span class="ID">SetNumberRows</span><span class="Operator">(</span><span class="Number">55</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 159 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">sheet1</span><span class="Operator">.</span><span class="ID">SetNumberCols</span><span class="Operator">(</span><span class="Number">25</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 160 </span>        <span class="ResWord">for</span> <span class="ID">i</span> <span class="ResWord">in</span> <span class="ID">range</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">sheet1</span><span class="Operator">.</span><span class="ID">GetNumberRows</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 161 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">sheet1</span><span class="Operator">.</span><span class="ID">SetRowSize</span><span class="Operator">(</span><span class="ID">i</span><span class="Operator">,</span> <span class="Number">20</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 162 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">sheet1</span><span class="Operator">.</span><span class="ID">SetFocus</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 163 </span>        <span class="ID">box</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">sheet1</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 164 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">CreateStatusBar</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 165 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 166 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 167 </span></span>
<span class="line"><span class="LineNumber"> 168 </span>    <span class="ResWord">def</span> <span class="ID">OnUndo</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 169 </span>        <span class="ResWord">if</span> <span class="ID">len</span><span class="Operator">(</span><span class="ID">stockUndo</span><span class="Operator">)</span> <span class="Operator">==</span> <span class="Number">0</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 170 </span>            <span class="ResWord">return</span></span>
<span class="line"><span class="LineNumber"> 171 </span></span>
<span class="line"><span class="LineNumber"> 172 </span>        <span class="ID">a</span> <span class="Operator">=</span> <span class="ID">stockUndo</span><span class="Operator">.</span><span class="ID">pop</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 173 </span>        <span class="ResWord">if</span> <span class="ID">len</span><span class="Operator">(</span><span class="ID">stockUndo</span><span class="Operator">)</span> <span class="Operator">==</span> <span class="Number">0</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 174 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">toolbar1</span><span class="Operator">.</span><span class="ID">EnableTool</span><span class="Operator">(</span><span class="Number">808</span><span class="Operator">,</span> <span class="ID">False</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 175 </span></span>
<span class="line"><span class="LineNumber"> 176 </span>        <span class="ID">a</span><span class="Operator">.</span><span class="ID">undo</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 177 </span>        <span class="ID">stockRedo</span><span class="Operator">.</span><span class="ID">append</span><span class="Operator">(</span><span class="ID">a</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 178 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">toolbar1</span><span class="Operator">.</span><span class="ID">EnableTool</span><span class="Operator">(</span><span class="Number">809</span><span class="Operator">,</span> <span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 179 </span></span>
<span class="line"><span class="LineNumber"> 180 </span>    <span class="ResWord">def</span> <span class="ID">OnRedo</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 181 </span>        <span class="ResWord">if</span> <span class="ID">len</span><span class="Operator">(</span><span class="ID">stockRedo</span><span class="Operator">)</span> <span class="Operator">==</span> <span class="Number">0</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 182 </span>            <span class="ResWord">return</span></span>
<span class="line"><span class="LineNumber"> 183 </span></span>
<span class="line"><span class="LineNumber"> 184 </span>        <span class="ID">a</span> <span class="Operator">=</span> <span class="ID">stockRedo</span><span class="Operator">.</span><span class="ID">pop</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 185 </span>        <span class="ResWord">if</span> <span class="ID">len</span><span class="Operator">(</span><span class="ID">stockRedo</span><span class="Operator">)</span> <span class="Operator">==</span> <span class="Number">0</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 186 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">toolbar1</span><span class="Operator">.</span><span class="ID">EnableTool</span><span class="Operator">(</span><span class="Number">809</span><span class="Operator">,</span> <span class="ID">False</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 187 </span></span>
<span class="line"><span class="LineNumber"> 188 </span>        <span class="ID">a</span><span class="Operator">.</span><span class="ID">redo</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 189 </span>        <span class="ID">stockUndo</span><span class="Operator">.</span><span class="ID">append</span><span class="Operator">(</span><span class="ID">a</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 190 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">toolbar1</span><span class="Operator">.</span><span class="ID">EnableTool</span><span class="Operator">(</span><span class="Number">808</span><span class="Operator">,</span> <span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 191 </span></span>
<span class="line"><span class="LineNumber"> 192 </span>    <span class="ResWord">def</span> <span class="ID">OnQuitNewt</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 193 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Close</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 194 </span></span>
<span class="line"><span class="LineNumber"> 195 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">PySimpleApp</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 196 </span><span class="ID">newt</span> <span class="Operator">=</span> <span class="ID">Newt</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">"Newt"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 197 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-4956"></span><p class="line874">In
 our example, we want to undo and redo cell text changes and column and 
row size changes. So we must bind relevant events to our methods. These 
bindings are not visible in our sample code. You can find them in 
sheet.py file, in CSheet class: <span class="anchor" id="line-4957"></span><span class="anchor" id="line-4958"></span></p><p class="line867"><span class="anchor" id="line-4959"></span><span class="anchor" id="line-4960"></span><span class="anchor" id="line-4961"></span><span class="anchor" id="line-4962"></span></p><pre>self.Bind(wx.grid.EVT_GRID_ROW_SIZE, self.OnRowSize)
self.Bind(wx.grid.EVT_GRID_COL_SIZE, self.OnColSize)
self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnCellChange)</pre><span class="anchor" id="line-4963"></span><p class="line862">In these three methods we create Undo objects. These objects are<tt>UndoText</tt>, <tt>UndoColSize</tt> and <tt>UndoRowSize</tt>. Each object has two methods. <tt>undo()</tt> and <tt>redo()</tt>.
 They are responsible for bringing to the state of the application 
before the change was done and vice versa. The objects are then appended
 to stockUndo list. This way we ensure, that all necessary changes are 
stored. Finally, when we press undo, redo buttons, we call <tt>OnUndo()</tt> and <tt>OnRedo()</tt> methods. The following method calls actually do the job: <span class="anchor" id="line-4964"></span><span class="anchor" id="line-4965"></span></p><p class="line867"><span class="anchor" id="line-4966"></span><span class="anchor" id="line-4967"></span><span class="anchor" id="line-4968"></span></p><pre>a.undo()
a.redo()</pre><span class="anchor" id="line-4969"></span><p class="line862">The
 objects move between stockUndo and stockRedo lists accordingly. Also 
when there are no objects left, we disable a button with the<tt>EnableTool()</tt> method. <span class="anchor" id="line-4970"></span><span class="anchor" id="line-4971"></span></p><p class="line867"><img alt="newt.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_043.png" title="newt.png"> <span class="anchor" id="line-4972"></span><span class="anchor" id="line-4973"></span></p><p class="line867"><strong>Figure: newt.py</strong> <span class="anchor" id="line-4974"></span><span class="anchor" id="line-4975"></span></p><p class="line867">
</p><h2 id="Gripts">Gripts</h2>
<span class="anchor" id="line-4976"></span><p class="line874">In this 
section we will show some small, complete scripts. These graphical 
scripts or "gripts" will demonstrate various areas in programming.  
Programming in Python, wxPython is easier than in most other toolkits. 
But it is still a laborious task. There is a long, long way from easy 
scripts to professional applications. <span class="anchor" id="line-4977"></span><span class="anchor" id="line-4978"></span></p><p class="line867">
</p><h3 id="Tom">Tom</h3>
<span class="anchor" id="line-4979"></span><p class="line874">Each application should have a good name. Short and easily remembered. So, we have Tom. A simple gript that  sends an email. <span class="anchor" id="line-4980"></span><span class="anchor" id="line-4981"></span></p><p class="line867"><span class="anchor" id="line-4982"></span><span class="anchor" id="line-4983"></span><span class="anchor" id="line-4984"></span><span class="anchor" id="line-4985"></span><span class="anchor" id="line-4986"></span><span class="anchor" id="line-4987"></span><span class="anchor" id="line-4988"></span><span class="anchor" id="line-4989"></span><span class="anchor" id="line-4990"></span><span class="anchor" id="line-4991"></span><span class="anchor" id="line-4992"></span><span class="anchor" id="line-4993"></span><span class="anchor" id="line-4994"></span><span class="anchor" id="line-4995"></span><span class="anchor" id="line-4996"></span><span class="anchor" id="line-4997"></span><span class="anchor" id="line-4998"></span><span class="anchor" id="line-4999"></span><span class="anchor" id="line-5000"></span><span class="anchor" id="line-5001"></span><span class="anchor" id="line-5002"></span><span class="anchor" id="line-5003"></span><span class="anchor" id="line-5004"></span><span class="anchor" id="line-5005"></span><span class="anchor" id="line-5006"></span><span class="anchor" id="line-5007"></span><span class="anchor" id="line-5008"></span><span class="anchor" id="line-5009"></span><span class="anchor" id="line-5010"></span><span class="anchor" id="line-5011"></span><span class="anchor" id="line-5012"></span><span class="anchor" id="line-5013"></span><span class="anchor" id="line-5014"></span><span class="anchor" id="line-5015"></span><span class="anchor" id="line-5016"></span><span class="anchor" id="line-5017"></span><span class="anchor" id="line-5018"></span><span class="anchor" id="line-5019"></span><span class="anchor" id="line-5020"></span><span class="anchor" id="line-5021"></span><span class="anchor" id="line-5022"></span><span class="anchor" id="line-5023"></span><span class="anchor" id="line-5024"></span><span class="anchor" id="line-5025"></span><span class="anchor" id="line-5026"></span><span class="anchor" id="line-5027"></span><span class="anchor" id="line-5028"></span><span class="anchor" id="line-5029"></span><span class="anchor" id="line-5030"></span><span class="anchor" id="line-5031"></span><span class="anchor" id="line-5032"></span><span class="anchor" id="line-5033"></span><span class="anchor" id="line-5034"></span><span class="anchor" id="line-5035"></span><span class="anchor" id="line-5036"></span><span class="anchor" id="line-5037"></span><span class="anchor" id="line-5038"></span><span class="anchor" id="line-5039"></span><span class="anchor" id="line-5040"></span><span class="anchor" id="line-5041"></span><span class="anchor" id="line-5042"></span><span class="anchor" id="line-5043"></span><span class="anchor" id="line-5044"></span><span class="anchor" id="line-5045"></span><span class="anchor" id="line-5046"></span><span class="anchor" id="line-5047"></span><span class="anchor" id="line-5048"></span><span class="anchor" id="line-5049"></span><span class="anchor" id="line-5050"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-5b7bc3fa5c8cff17758d79989b8c91f628b3dd7c\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-5b7bc3fa5c8cff17758d79989b8c91f628b3dd7c', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-5b7bc3fa5c8cff17758d79989b8c91f628b3dd7c" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># Tom</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span><span class="ResWord">import</span> <span class="ID">smtplib</span></span>
<span class="line"><span class="LineNumber">   7 </span></span>
<span class="line"><span class="LineNumber">   8 </span><span class="ResWord">class</span> <span class="ID">Tom</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Dialog</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  10 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Dialog</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">DefaultPosition</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Size</span><span class="Operator">(</span><span class="Number">400</span><span class="Operator">,</span> <span class="Number">420</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  11 </span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">panel</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Panel</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">vbox</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BoxSizer</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">VERTICAL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">hbox1</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BoxSizer</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">HORIZONTAL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">hbox2</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BoxSizer</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">HORIZONTAL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span>        <span class="ID">hbox3</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BoxSizer</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">HORIZONTAL</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="ID">st1</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'From: '</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  18 </span>        <span class="ID">st2</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'To: '</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  19 </span>        <span class="ID">st3</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Subject: '</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  20 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tc1</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TextCtrl</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">180</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  21 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tc2</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TextCtrl</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">180</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  22 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tc3</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TextCtrl</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">180</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  23 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">write</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TextCtrl</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">TE_MULTILINE</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  24 </span>        <span class="ID">button_send</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">panel</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="String">'Send'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  25 </span>        <span class="ID">hbox1</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">st1</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">LEFT</span><span class="Operator">,</span> <span class="Number">10</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  26 </span>        <span class="ID">hbox1</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">tc1</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">LEFT</span><span class="Operator">,</span> <span class="Number">20</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  27 </span>        <span class="ID">hbox2</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">st2</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">LEFT</span><span class="Operator">,</span> <span class="Number">10</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  28 </span>        <span class="ID">hbox2</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">tc2</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">LEFT</span><span class="Operator">,</span> <span class="Number">35</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  29 </span>        <span class="ID">hbox3</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">st3</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">LEFT</span><span class="Operator">,</span> <span class="Number">10</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  30 </span>        <span class="ID">hbox3</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">tc3</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  31 </span>        <span class="ID">vbox</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">hbox1</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TOP</span><span class="Operator">,</span> <span class="Number">10</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  32 </span>        <span class="ID">vbox</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">hbox2</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TOP</span><span class="Operator">,</span> <span class="Number">10</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  33 </span>        <span class="ID">vbox</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">hbox3</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TOP</span><span class="Operator">,</span> <span class="Number">10</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  34 </span>        <span class="ID">vbox</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">write</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">EXPAND</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TOP</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">RIGHT</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">LEFT</span><span class="Operator">,</span> <span class="Number">15</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  35 </span>        <span class="ID">vbox</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span><span class="ID">button_send</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ALIGN_CENTER</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TOP</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">BOTTOM</span><span class="Operator">,</span> <span class="Number">20</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  36 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnSend</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  37 </span>        <span class="ID">panel</span><span class="Operator">.</span><span class="ID">SetSizer</span><span class="Operator">(</span><span class="ID">vbox</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  38 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  39 </span></span>
<span class="line"><span class="LineNumber">  40 </span>    <span class="ResWord">def</span> <span class="ID">OnSend</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  41 </span>        <span class="ID">sender</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tc1</span><span class="Operator">.</span><span class="ID">GetValue</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  42 </span>        <span class="ID">recipient</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tc2</span><span class="Operator">.</span><span class="ID">GetValue</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  43 </span>        <span class="ID">subject</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tc3</span><span class="Operator">.</span><span class="ID">GetValue</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  44 </span>        <span class="ID">text</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">write</span><span class="Operator">.</span><span class="ID">GetValue</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  45 </span>        <span class="ID">header</span> <span class="Operator">=</span> <span class="String">'From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n'</span> <span class="Operator">%</span> <span class="Operator">(</span><span class="ID">sender</span><span class="Operator">,</span> <span class="ID">recipient</span><span class="Operator">,</span> <span class="ID">subject</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  46 </span>        <span class="ID">message</span> <span class="Operator">=</span> <span class="ID">header</span> <span class="Operator">+</span> <span class="ID">text</span></span>
<span class="line"><span class="LineNumber">  47 </span>        <span class="ResWord">try</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  48 </span>            <span class="ID">server</span> <span class="Operator">=</span> <span class="ID">smtplib</span><span class="Operator">.</span><span class="ID">SMTP</span><span class="Operator">(</span><span class="String">'mail.chello.sk'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  49 </span>            <span class="ID">server</span><span class="Operator">.</span><span class="ID">sendmail</span><span class="Operator">(</span><span class="ID">sender</span><span class="Operator">,</span> <span class="ID">recipient</span><span class="Operator">,</span> <span class="ID">message</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  50 </span>            <span class="ID">server</span><span class="Operator">.</span><span class="ID">quit</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  51 </span>            <span class="ID">dlg</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MessageDialog</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="String">'Email was successfully sent'</span><span class="Operator">,</span> <span class="String">'Success'</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">OK</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ICON_INFORMATION</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  52 </span>            <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">ShowModal</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  53 </span>            <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">Destroy</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  54 </span>        <span class="ResWord">except</span> <span class="ID">smtplib</span><span class="Operator">.</span><span class="ID">SMTPException</span><span class="Operator">,</span> <span class="ID">error</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  55 </span>            <span class="ID">dlg</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MessageDialog</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="String">'Failed to send email'</span><span class="Operator">,</span> <span class="String">'Error'</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">OK</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ICON_ERROR</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  56 </span>            <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">ShowModal</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  57 </span>            <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">Destroy</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  58 </span></span>
<span class="line"><span class="LineNumber">  59 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  60 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  61 </span>        <span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">Tom</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Tom'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  62 </span>        <span class="ID">frame</span><span class="Operator">.</span><span class="ID">ShowModal</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  63 </span>        <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Destroy</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  64 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  65 </span></span>
<span class="line"><span class="LineNumber">  66 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  67 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-5051"></span><p class="line874">For working with emails we need to import smtp module. <span class="anchor" id="line-5052"></span><span class="anchor" id="line-5053"></span></p><p class="line867"><span class="anchor" id="line-5054"></span><span class="anchor" id="line-5055"></span></p><pre>import smtplib</pre><span class="anchor" id="line-5056"></span><p class="line874">From,
 To and Subject options must be separated by carriedge return and 
newline as shown here. This weird thing is requested by RFC 821 norm. So
 we must follow it. <span class="anchor" id="line-5057"></span><span class="anchor" id="line-5058"></span></p><p class="line867"><span class="anchor" id="line-5059"></span><span class="anchor" id="line-5060"></span></p><pre>header = 'From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n' % (sender, recipient, subject)</pre><span class="anchor" id="line-5061"></span><p class="line874">Next
 we create an SMTP connection. Here you specify your settings. Each ISP 
gives you the name of the  pop and smtp servers. In my case, 
'mail.chello.sk' is a name for both.  A mail is sent by calling the 
sendmail() method. Finally, we quit the connection with the quit() 
method. <span class="anchor" id="line-5062"></span><span class="anchor" id="line-5063"></span></p><p class="line867"><span class="anchor" id="line-5064"></span><span class="anchor" id="line-5065"></span><span class="anchor" id="line-5066"></span><span class="anchor" id="line-5067"></span></p><pre>server = smtplib.SMTP('mail.chello.sk')
server.sendmail(sender, recipient, message)
server.quit()</pre><span class="anchor" id="line-5068"></span><p class="line867"><img alt="tom.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_035.png" title="tom.png"> <span class="anchor" id="line-5069"></span><span class="anchor" id="line-5070"></span></p><p class="line867"><strong>Figure: Tom</strong> <span class="anchor" id="line-5071"></span><span class="anchor" id="line-5072"></span></p><p class="line867">
</p><h3 id="Editor">Editor</h3>
<span class="anchor" id="line-5073"></span><p class="line874">Here we 
have a simple text editor. Notice the use of exceptions. It is a 
programmer's task to find and handle bugs. This includes doing such 
nasty things like opening pictures in an editor, simulating all possible
 situations. If a script raises an unhandled exception, we simply write 
 a code that handles this. <span class="anchor" id="line-5074"></span><span class="anchor" id="line-5075"></span></p><p class="line867"><span class="anchor" id="line-5076"></span><span class="anchor" id="line-5077"></span><span class="anchor" id="line-5078"></span><span class="anchor" id="line-5079"></span><span class="anchor" id="line-5080"></span><span class="anchor" id="line-5081"></span><span class="anchor" id="line-5082"></span><span class="anchor" id="line-5083"></span><span class="anchor" id="line-5084"></span><span class="anchor" id="line-5085"></span><span class="anchor" id="line-5086"></span><span class="anchor" id="line-5087"></span><span class="anchor" id="line-5088"></span><span class="anchor" id="line-5089"></span><span class="anchor" id="line-5090"></span><span class="anchor" id="line-5091"></span><span class="anchor" id="line-5092"></span><span class="anchor" id="line-5093"></span><span class="anchor" id="line-5094"></span><span class="anchor" id="line-5095"></span><span class="anchor" id="line-5096"></span><span class="anchor" id="line-5097"></span><span class="anchor" id="line-5098"></span><span class="anchor" id="line-5099"></span><span class="anchor" id="line-5100"></span><span class="anchor" id="line-5101"></span><span class="anchor" id="line-5102"></span><span class="anchor" id="line-5103"></span><span class="anchor" id="line-5104"></span><span class="anchor" id="line-5105"></span><span class="anchor" id="line-5106"></span><span class="anchor" id="line-5107"></span><span class="anchor" id="line-5108"></span><span class="anchor" id="line-5109"></span><span class="anchor" id="line-5110"></span><span class="anchor" id="line-5111"></span><span class="anchor" id="line-5112"></span><span class="anchor" id="line-5113"></span><span class="anchor" id="line-5114"></span><span class="anchor" id="line-5115"></span><span class="anchor" id="line-5116"></span><span class="anchor" id="line-5117"></span><span class="anchor" id="line-5118"></span><span class="anchor" id="line-5119"></span><span class="anchor" id="line-5120"></span><span class="anchor" id="line-5121"></span><span class="anchor" id="line-5122"></span><span class="anchor" id="line-5123"></span><span class="anchor" id="line-5124"></span><span class="anchor" id="line-5125"></span><span class="anchor" id="line-5126"></span><span class="anchor" id="line-5127"></span><span class="anchor" id="line-5128"></span><span class="anchor" id="line-5129"></span><span class="anchor" id="line-5130"></span><span class="anchor" id="line-5131"></span><span class="anchor" id="line-5132"></span><span class="anchor" id="line-5133"></span><span class="anchor" id="line-5134"></span><span class="anchor" id="line-5135"></span><span class="anchor" id="line-5136"></span><span class="anchor" id="line-5137"></span><span class="anchor" id="line-5138"></span><span class="anchor" id="line-5139"></span><span class="anchor" id="line-5140"></span><span class="anchor" id="line-5141"></span><span class="anchor" id="line-5142"></span><span class="anchor" id="line-5143"></span><span class="anchor" id="line-5144"></span><span class="anchor" id="line-5145"></span><span class="anchor" id="line-5146"></span><span class="anchor" id="line-5147"></span><span class="anchor" id="line-5148"></span><span class="anchor" id="line-5149"></span><span class="anchor" id="line-5150"></span><span class="anchor" id="line-5151"></span><span class="anchor" id="line-5152"></span><span class="anchor" id="line-5153"></span><span class="anchor" id="line-5154"></span><span class="anchor" id="line-5155"></span><span class="anchor" id="line-5156"></span><span class="anchor" id="line-5157"></span><span class="anchor" id="line-5158"></span><span class="anchor" id="line-5159"></span><span class="anchor" id="line-5160"></span><span class="anchor" id="line-5161"></span><span class="anchor" id="line-5162"></span><span class="anchor" id="line-5163"></span><span class="anchor" id="line-5164"></span><span class="anchor" id="line-5165"></span><span class="anchor" id="line-5166"></span><span class="anchor" id="line-5167"></span><span class="anchor" id="line-5168"></span><span class="anchor" id="line-5169"></span><span class="anchor" id="line-5170"></span><span class="anchor" id="line-5171"></span><span class="anchor" id="line-5172"></span><span class="anchor" id="line-5173"></span><span class="anchor" id="line-5174"></span><span class="anchor" id="line-5175"></span><span class="anchor" id="line-5176"></span><span class="anchor" id="line-5177"></span><span class="anchor" id="line-5178"></span><span class="anchor" id="line-5179"></span><span class="anchor" id="line-5180"></span><span class="anchor" id="line-5181"></span><span class="anchor" id="line-5182"></span><span class="anchor" id="line-5183"></span><span class="anchor" id="line-5184"></span><span class="anchor" id="line-5185"></span><span class="anchor" id="line-5186"></span><span class="anchor" id="line-5187"></span><span class="anchor" id="line-5188"></span><span class="anchor" id="line-5189"></span><span class="anchor" id="line-5190"></span><span class="anchor" id="line-5191"></span><span class="anchor" id="line-5192"></span><span class="anchor" id="line-5193"></span><span class="anchor" id="line-5194"></span><span class="anchor" id="line-5195"></span><span class="anchor" id="line-5196"></span><span class="anchor" id="line-5197"></span><span class="anchor" id="line-5198"></span><span class="anchor" id="line-5199"></span><span class="anchor" id="line-5200"></span><span class="anchor" id="line-5201"></span><span class="anchor" id="line-5202"></span><span class="anchor" id="line-5203"></span><span class="anchor" id="line-5204"></span><span class="anchor" id="line-5205"></span><span class="anchor" id="line-5206"></span><span class="anchor" id="line-5207"></span><span class="anchor" id="line-5208"></span><span class="anchor" id="line-5209"></span><span class="anchor" id="line-5210"></span><span class="anchor" id="line-5211"></span><span class="anchor" id="line-5212"></span><span class="anchor" id="line-5213"></span><span class="anchor" id="line-5214"></span><span class="anchor" id="line-5215"></span><span class="anchor" id="line-5216"></span><span class="anchor" id="line-5217"></span><span class="anchor" id="line-5218"></span><span class="anchor" id="line-5219"></span><span class="anchor" id="line-5220"></span><span class="anchor" id="line-5221"></span><span class="anchor" id="line-5222"></span><span class="anchor" id="line-5223"></span><span class="anchor" id="line-5224"></span><span class="anchor" id="line-5225"></span><span class="anchor" id="line-5226"></span><span class="anchor" id="line-5227"></span><span class="anchor" id="line-5228"></span><span class="anchor" id="line-5229"></span><span class="anchor" id="line-5230"></span><span class="anchor" id="line-5231"></span><span class="anchor" id="line-5232"></span><span class="anchor" id="line-5233"></span><span class="anchor" id="line-5234"></span><span class="anchor" id="line-5235"></span><span class="anchor" id="line-5236"></span><span class="anchor" id="line-5237"></span><span class="anchor" id="line-5238"></span><span class="anchor" id="line-5239"></span><span class="anchor" id="line-5240"></span><span class="anchor" id="line-5241"></span><span class="anchor" id="line-5242"></span><span class="anchor" id="line-5243"></span><span class="anchor" id="line-5244"></span><span class="anchor" id="line-5245"></span><span class="anchor" id="line-5246"></span><span class="anchor" id="line-5247"></span><span class="anchor" id="line-5248"></span><span class="anchor" id="line-5249"></span><span class="anchor" id="line-5250"></span><span class="anchor" id="line-5251"></span><span class="anchor" id="line-5252"></span><span class="anchor" id="line-5253"></span><span class="anchor" id="line-5254"></span><span class="anchor" id="line-5255"></span><span class="anchor" id="line-5256"></span><span class="anchor" id="line-5257"></span><span class="anchor" id="line-5258"></span><span class="anchor" id="line-5259"></span><span class="anchor" id="line-5260"></span><span class="anchor" id="line-5261"></span><span class="anchor" id="line-5262"></span><span class="anchor" id="line-5263"></span><span class="anchor" id="line-5264"></span><span class="anchor" id="line-5265"></span><span class="anchor" id="line-5266"></span><span class="anchor" id="line-5267"></span><span class="anchor" id="line-5268"></span><span class="anchor" id="line-5269"></span><span class="anchor" id="line-5270"></span><span class="anchor" id="line-5271"></span><span class="anchor" id="line-5272"></span><span class="anchor" id="line-5273"></span><span class="anchor" id="line-5274"></span><span class="anchor" id="line-5275"></span><span class="anchor" id="line-5276"></span><span class="anchor" id="line-5277"></span><span class="anchor" id="line-5278"></span><span class="anchor" id="line-5279"></span><span class="anchor" id="line-5280"></span><span class="anchor" id="line-5281"></span><span class="anchor" id="line-5282"></span><span class="anchor" id="line-5283"></span><span class="anchor" id="line-5284"></span><span class="anchor" id="line-5285"></span><span class="anchor" id="line-5286"></span><span class="anchor" id="line-5287"></span><span class="anchor" id="line-5288"></span><span class="anchor" id="line-5289"></span><span class="anchor" id="line-5290"></span><span class="anchor" id="line-5291"></span><span class="anchor" id="line-5292"></span><span class="anchor" id="line-5293"></span><span class="anchor" id="line-5294"></span><span class="anchor" id="line-5295"></span><span class="anchor" id="line-5296"></span><span class="anchor" id="line-5297"></span><span class="anchor" id="line-5298"></span><span class="anchor" id="line-5299"></span><span class="anchor" id="line-5300"></span><span class="anchor" id="line-5301"></span><span class="anchor" id="line-5302"></span><span class="anchor" id="line-5303"></span><span class="anchor" id="line-5304"></span><span class="anchor" id="line-5305"></span><span class="anchor" id="line-5306"></span><span class="anchor" id="line-5307"></span><span class="anchor" id="line-5308"></span><span class="anchor" id="line-5309"></span><span class="anchor" id="line-5310"></span><span class="anchor" id="line-5311"></span><span class="anchor" id="line-5312"></span><span class="anchor" id="line-5313"></span><span class="anchor" id="line-5314"></span><span class="anchor" id="line-5315"></span><span class="anchor" id="line-5316"></span><span class="anchor" id="line-5317"></span><span class="anchor" id="line-5318"></span><span class="anchor" id="line-5319"></span><span class="anchor" id="line-5320"></span><span class="anchor" id="line-5321"></span><span class="anchor" id="line-5322"></span><span class="anchor" id="line-5323"></span><span class="anchor" id="line-5324"></span><span class="anchor" id="line-5325"></span><span class="anchor" id="line-5326"></span><span class="anchor" id="line-5327"></span><span class="anchor" id="line-5328"></span><span class="anchor" id="line-5329"></span><span class="anchor" id="line-5330"></span><span class="anchor" id="line-5331"></span><span class="anchor" id="line-5332"></span><span class="anchor" id="line-5333"></span><span class="anchor" id="line-5334"></span><span class="anchor" id="line-5335"></span><span class="anchor" id="line-5336"></span><span class="anchor" id="line-5337"></span><span class="anchor" id="line-5338"></span><span class="anchor" id="line-5339"></span><span class="anchor" id="line-5340"></span><span class="anchor" id="line-5341"></span><span class="anchor" id="line-5342"></span><span class="anchor" id="line-5343"></span><span class="anchor" id="line-5344"></span><span class="anchor" id="line-5345"></span><span class="anchor" id="line-5346"></span><span class="anchor" id="line-5347"></span><span class="anchor" id="line-5348"></span><span class="anchor" id="line-5349"></span><span class="anchor" id="line-5350"></span><span class="anchor" id="line-5351"></span><span class="anchor" id="line-5352"></span><span class="anchor" id="line-5353"></span><span class="anchor" id="line-5354"></span><span class="anchor" id="line-5355"></span><span class="anchor" id="line-5356"></span><span class="anchor" id="line-5357"></span><span class="anchor" id="line-5358"></span><span class="anchor" id="line-5359"></span><span class="anchor" id="line-5360"></span><span class="anchor" id="line-5361"></span><span class="anchor" id="line-5362"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-4832eece13500a9fc2b903e4e229bff7c09c2ce7\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-4832eece13500a9fc2b903e4e229bff7c09c2ce7', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-4832eece13500a9fc2b903e4e229bff7c09c2ce7" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># Editor</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   6 </span><span class="ResWord">import</span> <span class="ID">os</span></span>
<span class="line"><span class="LineNumber">   7 </span></span>
<span class="line"><span class="LineNumber">   8 </span><span class="ResWord">class</span> <span class="ID">Editor</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  10 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">600</span><span class="Operator">,</span> <span class="Number">500</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  11 </span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="Comment"># variables</span></span>
<span class="line"><span class="LineNumber">  13 </span><span class="Comment"></span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">modify</span> <span class="Operator">=</span> <span class="ID">False</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">last_name_saved</span> <span class="Operator">=</span> <span class="String">''</span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">replace</span> <span class="Operator">=</span> <span class="ID">False</span></span>
<span class="line"><span class="LineNumber">  16 </span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="Comment"># setting up menubar</span></span>
<span class="line"><span class="LineNumber">  18 </span><span class="Comment"></span>        <span class="ID">menubar</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MenuBar</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  19 </span></span>
<span class="line"><span class="LineNumber">  20 </span>        <span class="ID">file</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Menu</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  21 </span>        <span class="ID">new</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MenuItem</span><span class="Operator">(</span><span class="ID">file</span><span class="Operator">,</span> <span class="Number">101</span><span class="Operator">,</span> <span class="String">'&amp;New\tCtrl+N'</span><span class="Operator">,</span> <span class="String">'Creates a new document'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  22 </span>        <span class="ID">new</span><span class="Operator">.</span><span class="ID">SetBitmap</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bitmap</span><span class="Operator">(</span><span class="String">'icons/stock_new-16.png'</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  23 </span>        <span class="ID">file</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">new</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  24 </span></span>
<span class="line"><span class="LineNumber">  25 </span>        <span class="ID">open</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MenuItem</span><span class="Operator">(</span><span class="ID">file</span><span class="Operator">,</span> <span class="Number">102</span><span class="Operator">,</span> <span class="String">'&amp;Open\tCtrl+O'</span><span class="Operator">,</span> <span class="String">'Open an existing file'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  26 </span>        <span class="ID">open</span><span class="Operator">.</span><span class="ID">SetBitmap</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bitmap</span><span class="Operator">(</span><span class="String">'icons/stock_open-16.png'</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  27 </span>        <span class="ID">file</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">open</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  28 </span>        <span class="ID">file</span><span class="Operator">.</span><span class="ID">AppendSeparator</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  29 </span></span>
<span class="line"><span class="LineNumber">  30 </span>        <span class="ID">save</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MenuItem</span><span class="Operator">(</span><span class="ID">file</span><span class="Operator">,</span> <span class="Number">103</span><span class="Operator">,</span> <span class="String">'&amp;Save\tCtrl+S'</span><span class="Operator">,</span> <span class="String">'Save the file'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  31 </span>        <span class="ID">save</span><span class="Operator">.</span><span class="ID">SetBitmap</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bitmap</span><span class="Operator">(</span><span class="String">'icons/stock_save-16.png'</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  32 </span>        <span class="ID">file</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">save</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  33 </span></span>
<span class="line"><span class="LineNumber">  34 </span>        <span class="ID">saveas</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MenuItem</span><span class="Operator">(</span><span class="ID">file</span><span class="Operator">,</span> <span class="Number">104</span><span class="Operator">,</span> <span class="String">'Save &amp;As...\tShift+Ctrl+S'</span><span class="Operator">,</span> <span class="String">'Save the file with a different name'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  35 </span>        <span class="ID">saveas</span><span class="Operator">.</span><span class="ID">SetBitmap</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bitmap</span><span class="Operator">(</span><span class="String">'icons/stock_save_as-16.png'</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  36 </span>        <span class="ID">file</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">saveas</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  37 </span>        <span class="ID">file</span><span class="Operator">.</span><span class="ID">AppendSeparator</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  38 </span></span>
<span class="line"><span class="LineNumber">  39 </span>        <span class="ID">quit</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MenuItem</span><span class="Operator">(</span><span class="ID">file</span><span class="Operator">,</span> <span class="Number">105</span><span class="Operator">,</span> <span class="String">'&amp;Quit\tCtrl+Q'</span><span class="Operator">,</span> <span class="String">'Quit the Application'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  40 </span>        <span class="ID">quit</span><span class="Operator">.</span><span class="ID">SetBitmap</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bitmap</span><span class="Operator">(</span><span class="String">'icons/stock_exit-16.png'</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  41 </span>        <span class="ID">file</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">quit</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  42 </span></span>
<span class="line"><span class="LineNumber">  43 </span>        <span class="ID">edit</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Menu</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  44 </span>        <span class="ID">cut</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MenuItem</span><span class="Operator">(</span><span class="ID">edit</span><span class="Operator">,</span> <span class="Number">106</span><span class="Operator">,</span> <span class="String">'&amp;Cut\tCtrl+X'</span><span class="Operator">,</span> <span class="String">'Cut the Selection'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  45 </span>        <span class="ID">cut</span><span class="Operator">.</span><span class="ID">SetBitmap</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bitmap</span><span class="Operator">(</span><span class="String">'icons/stock_cut-16.png'</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  46 </span>        <span class="ID">edit</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">cut</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  47 </span></span>
<span class="line"><span class="LineNumber">  48 </span>        <span class="ID">copy</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MenuItem</span><span class="Operator">(</span><span class="ID">edit</span><span class="Operator">,</span> <span class="Number">107</span><span class="Operator">,</span> <span class="String">'&amp;Copy\tCtrl+C'</span><span class="Operator">,</span> <span class="String">'Copy the Selection'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  49 </span>        <span class="ID">copy</span><span class="Operator">.</span><span class="ID">SetBitmap</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bitmap</span><span class="Operator">(</span><span class="String">'icons/stock_copy-16.png'</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  50 </span>        <span class="ID">edit</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">copy</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  51 </span></span>
<span class="line"><span class="LineNumber">  52 </span>        <span class="ID">paste</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MenuItem</span><span class="Operator">(</span><span class="ID">edit</span><span class="Operator">,</span> <span class="Number">108</span><span class="Operator">,</span> <span class="String">'&amp;Paste\tCtrl+V'</span><span class="Operator">,</span> <span class="String">'Paste text from clipboard'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  53 </span>        <span class="ID">paste</span><span class="Operator">.</span><span class="ID">SetBitmap</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bitmap</span><span class="Operator">(</span><span class="String">'icons/stock_paste-16.png'</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  54 </span>        <span class="ID">edit</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">paste</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  55 </span></span>
<span class="line"><span class="LineNumber">  56 </span>        <span class="ID">delete</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MenuItem</span><span class="Operator">(</span><span class="ID">edit</span><span class="Operator">,</span> <span class="Number">109</span><span class="Operator">,</span> <span class="String">'&amp;Delete'</span><span class="Operator">,</span> <span class="String">'Delete the selected text'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  57 </span>        <span class="ID">delete</span><span class="Operator">.</span><span class="ID">SetBitmap</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bitmap</span><span class="Operator">(</span><span class="String">'icons/stock_delete-16.png'</span><span class="Operator">,</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  58 </span></span>
<span class="line"><span class="LineNumber">  59 </span>        <span class="ID">edit</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">delete</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  60 </span>        <span class="ID">edit</span><span class="Operator">.</span><span class="ID">AppendSeparator</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  61 </span>        <span class="ID">edit</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="Number">110</span><span class="Operator">,</span> <span class="String">'Select &amp;All\tCtrl+A'</span><span class="Operator">,</span> <span class="String">'Select the entire text'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  62 </span></span>
<span class="line"><span class="LineNumber">  63 </span>        <span class="ID">view</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Menu</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  64 </span>        <span class="ID">view</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="Number">111</span><span class="Operator">,</span> <span class="String">'&amp;Statusbar'</span><span class="Operator">,</span> <span class="String">'Show StatusBar'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  65 </span></span>
<span class="line"><span class="LineNumber">  66 </span>        <span class="ID">help</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Menu</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  67 </span>        <span class="ID">about</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MenuItem</span><span class="Operator">(</span><span class="ID">help</span><span class="Operator">,</span> <span class="Number">112</span><span class="Operator">,</span> <span class="String">'&amp;About\tF1'</span><span class="Operator">,</span> <span class="String">'About Editor'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  68 </span>        <span class="ID">about</span><span class="Operator">.</span><span class="ID">SetBitmap</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bitmap</span><span class="Operator">(</span><span class="String">'icons/stock_about-16.png'</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  69 </span>        <span class="ID">help</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">about</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  70 </span></span>
<span class="line"><span class="LineNumber">  71 </span>        <span class="ID">menubar</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="ID">file</span><span class="Operator">,</span> <span class="String">'&amp;File'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  72 </span>        <span class="ID">menubar</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="ID">edit</span><span class="Operator">,</span> <span class="String">'&amp;Edit'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  73 </span>        <span class="ID">menubar</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="ID">view</span><span class="Operator">,</span> <span class="String">'&amp;View'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  74 </span>        <span class="ID">menubar</span><span class="Operator">.</span><span class="ID">Append</span><span class="Operator">(</span><span class="ID">help</span><span class="Operator">,</span> <span class="String">'&amp;Help'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  75 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetMenuBar</span><span class="Operator">(</span><span class="ID">menubar</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  76 </span></span>
<span class="line"><span class="LineNumber">  77 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_MENU</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">NewApplication</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">101</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  78 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_MENU</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnOpenFile</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">102</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  79 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_MENU</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnSaveFile</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">103</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  80 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_MENU</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnSaveAsFile</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">104</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  81 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_MENU</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">QuitApplication</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">105</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  82 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_MENU</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnCut</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">106</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  83 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_MENU</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnCopy</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">107</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  84 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_MENU</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnPaste</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">108</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  85 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_MENU</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnDelete</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">109</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  86 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_MENU</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnSelectAll</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">110</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  87 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_MENU</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">ToggleStatusBar</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">111</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  88 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_MENU</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnAbout</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">112</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  89 </span></span>
<span class="line"><span class="LineNumber">  90 </span>        <span class="Comment"># setting up toolbar</span></span>
<span class="line"><span class="LineNumber">  91 </span><span class="Comment"></span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">toolbar</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">CreateToolBar</span><span class="Operator">(</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TB_HORIZONTAL</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">NO_BORDER</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TB_FLAT</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TB_TEXT</span> <span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  92 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">toolbar</span><span class="Operator">.</span><span class="ID">AddSimpleTool</span><span class="Operator">(</span><span class="Number">801</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bitmap</span><span class="Operator">(</span><span class="String">'icons/stock_new.png'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="String">'New'</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  93 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">toolbar</span><span class="Operator">.</span><span class="ID">AddSimpleTool</span><span class="Operator">(</span><span class="Number">802</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bitmap</span><span class="Operator">(</span><span class="String">'icons/stock_open.png'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="String">'Open'</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  94 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">toolbar</span><span class="Operator">.</span><span class="ID">AddSimpleTool</span><span class="Operator">(</span><span class="Number">803</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bitmap</span><span class="Operator">(</span><span class="String">'icons/stock_save.png'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="String">'Save'</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  95 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">toolbar</span><span class="Operator">.</span><span class="ID">AddSeparator</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  96 </span></span>
<span class="line"><span class="LineNumber">  97 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">toolbar</span><span class="Operator">.</span><span class="ID">AddSimpleTool</span><span class="Operator">(</span><span class="Number">804</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bitmap</span><span class="Operator">(</span><span class="String">'icons/stock_cut.png'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="String">'Cut'</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  98 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">toolbar</span><span class="Operator">.</span><span class="ID">AddSimpleTool</span><span class="Operator">(</span><span class="Number">805</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bitmap</span><span class="Operator">(</span><span class="String">'icons/stock_copy.png'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="String">'Copy'</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  99 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">toolbar</span><span class="Operator">.</span><span class="ID">AddSimpleTool</span><span class="Operator">(</span><span class="Number">806</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bitmap</span><span class="Operator">(</span><span class="String">'icons/stock_paste.png'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="String">'Paste'</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 100 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">toolbar</span><span class="Operator">.</span><span class="ID">AddSeparator</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 101 </span></span>
<span class="line"><span class="LineNumber"> 102 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">toolbar</span><span class="Operator">.</span><span class="ID">AddSimpleTool</span><span class="Operator">(</span><span class="Number">807</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bitmap</span><span class="Operator">(</span><span class="String">'icons/stock_exit.png'</span><span class="Operator">)</span><span class="Operator">,</span> <span class="String">'Exit'</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 103 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">toolbar</span><span class="Operator">.</span><span class="ID">Realize</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 104 </span></span>
<span class="line"><span class="LineNumber"> 105 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_TOOL</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">NewApplication</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">801</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 106 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_TOOL</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnOpenFile</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">802</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 107 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_TOOL</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnSaveFile</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">803</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 108 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_TOOL</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnCut</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">804</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 109 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_TOOL</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnCopy</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">805</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 110 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_TOOL</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnPaste</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">806</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 111 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_TOOL</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">QuitApplication</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">807</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 112 </span></span>
<span class="line"><span class="LineNumber"> 113 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">text</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TextCtrl</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">1000</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">=</span><span class="Operator">(</span><span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">TE_MULTILINE</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TE_PROCESS_ENTER</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 114 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">text</span><span class="Operator">.</span><span class="ID">SetFocus</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 115 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">text</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_TEXT</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnTextChanged</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">1000</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 116 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">text</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_KEY_DOWN</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnKeyDown</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 117 </span></span>
<span class="line"><span class="LineNumber"> 118 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_CLOSE</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">QuitApplication</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 119 </span></span>
<span class="line"><span class="LineNumber"> 120 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">StatusBar</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 121 </span></span>
<span class="line"><span class="LineNumber"> 122 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 123 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 124 </span></span>
<span class="line"><span class="LineNumber"> 125 </span>    <span class="ResWord">def</span> <span class="ID">NewApplication</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 126 </span>        <span class="ID">editor</span> <span class="Operator">=</span> <span class="ID">Editor</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Editor'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 127 </span>        <span class="ID">editor</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 128 </span>        <span class="ID">editor</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 129 </span></span>
<span class="line"><span class="LineNumber"> 130 </span>    <span class="ResWord">def</span> <span class="ID">OnOpenFile</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 131 </span>        <span class="ID">file_name</span> <span class="Operator">=</span> <span class="ID">os</span><span class="Operator">.</span><span class="ID">path</span><span class="Operator">.</span><span class="ID">basename</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">last_name_saved</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 132 </span>        <span class="ResWord">if</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">modify</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 133 </span>            <span class="ID">dlg</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MessageDialog</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="String">'Save changes?'</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">YES_NO</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">YES_DEFAULT</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">CANCEL</span> <span class="Operator">|</span></span>
<span class="line"><span class="LineNumber"> 134 </span>                        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ICON_QUESTION</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 135 </span>            <span class="ID">val</span> <span class="Operator">=</span> <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">ShowModal</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 136 </span>            <span class="ResWord">if</span> <span class="ID">val</span> <span class="Operator">==</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ID_YES</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 137 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnSaveFile</span><span class="Operator">(</span><span class="ID">event</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 138 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">DoOpenFile</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 139 </span>            <span class="ResWord">elif</span> <span class="ID">val</span> <span class="Operator">==</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ID_CANCEL</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 140 </span>                <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">Destroy</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 141 </span>            <span class="ResWord">else</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 142 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">DoOpenFile</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 143 </span>        <span class="ResWord">else</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 144 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">DoOpenFile</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 145 </span></span>
<span class="line"><span class="LineNumber"> 146 </span>    <span class="ResWord">def</span> <span class="ID">DoOpenFile</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 147 </span>        <span class="ID">wcd</span> <span class="Operator">=</span> <span class="String">'All files (*)|*|Editor files (*.ef)|*.ef|'</span></span>
<span class="line"><span class="LineNumber"> 148 </span>        <span class="ID">dir</span> <span class="Operator">=</span> <span class="ID">os</span><span class="Operator">.</span><span class="ID">getcwd</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 149 </span>        <span class="ID">open_dlg</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">FileDialog</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">message</span><span class="Operator">=</span><span class="String">'Choose a file'</span><span class="Operator">,</span> <span class="ID">defaultDir</span><span class="Operator">=</span><span class="ID">dir</span><span class="Operator">,</span> <span class="ID">defaultFile</span><span class="Operator">=</span><span class="String">''</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 150 </span>                        <span class="ID">wildcard</span><span class="Operator">=</span><span class="ID">wcd</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">OPEN</span><span class="Operator">|</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">CHANGE_DIR</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 151 </span>        <span class="ResWord">if</span> <span class="ID">open_dlg</span><span class="Operator">.</span><span class="ID">ShowModal</span><span class="Operator">(</span><span class="Operator">)</span> <span class="Operator">==</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ID_OK</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 152 </span>            <span class="ID">path</span> <span class="Operator">=</span> <span class="ID">open_dlg</span><span class="Operator">.</span><span class="ID">GetPath</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 153 </span></span>
<span class="line"><span class="LineNumber"> 154 </span>            <span class="ResWord">try</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 155 </span>                <span class="ID">file</span> <span class="Operator">=</span> <span class="ID">open</span><span class="Operator">(</span><span class="ID">path</span><span class="Operator">,</span> <span class="String">'r'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 156 </span>                <span class="ID">text</span> <span class="Operator">=</span> <span class="ID">file</span><span class="Operator">.</span><span class="ID">read</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 157 </span>                <span class="ID">file</span><span class="Operator">.</span><span class="ID">close</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 158 </span>                <span class="ResWord">if</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">text</span><span class="Operator">.</span><span class="ID">GetLastPosition</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 159 </span>                    <span class="ID">self</span><span class="Operator">.</span><span class="ID">text</span><span class="Operator">.</span><span class="ID">Clear</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 160 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">text</span><span class="Operator">.</span><span class="ID">WriteText</span><span class="Operator">(</span><span class="ID">text</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 161 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">last_name_saved</span> <span class="Operator">=</span> <span class="ID">path</span></span>
<span class="line"><span class="LineNumber"> 162 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">statusbar</span><span class="Operator">.</span><span class="ID">SetStatusText</span><span class="Operator">(</span><span class="String">''</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 163 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">modify</span> <span class="Operator">=</span> <span class="ID">False</span></span>
<span class="line"><span class="LineNumber"> 164 </span></span>
<span class="line"><span class="LineNumber"> 165 </span>            <span class="ResWord">except</span> <span class="ID">IOError</span><span class="Operator">,</span> <span class="ID">error</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 166 </span>                <span class="ID">dlg</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MessageDialog</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="String">'Error opening file\n'</span> <span class="Operator">+</span> <span class="ID">str</span><span class="Operator">(</span><span class="ID">error</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 167 </span>                <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">ShowModal</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 168 </span></span>
<span class="line"><span class="LineNumber"> 169 </span>            <span class="ResWord">except</span> <span class="ID">UnicodeDecodeError</span><span class="Operator">,</span> <span class="ID">error</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 170 </span>                <span class="ID">dlg</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MessageDialog</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="String">'Error opening file\n'</span> <span class="Operator">+</span> <span class="ID">str</span><span class="Operator">(</span><span class="ID">error</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 171 </span>                <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">ShowModal</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 172 </span></span>
<span class="line"><span class="LineNumber"> 173 </span>        <span class="ID">open_dlg</span><span class="Operator">.</span><span class="ID">Destroy</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 174 </span></span>
<span class="line"><span class="LineNumber"> 175 </span>    <span class="ResWord">def</span> <span class="ID">OnSaveFile</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 176 </span>        <span class="ResWord">if</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">last_name_saved</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 177 </span></span>
<span class="line"><span class="LineNumber"> 178 </span>            <span class="ResWord">try</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 179 </span>                <span class="ID">file</span> <span class="Operator">=</span> <span class="ID">open</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">last_name_saved</span><span class="Operator">,</span> <span class="String">'w'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 180 </span>                <span class="ID">text</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">text</span><span class="Operator">.</span><span class="ID">GetValue</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 181 </span>                <span class="ID">file</span><span class="Operator">.</span><span class="ID">write</span><span class="Operator">(</span><span class="ID">text</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 182 </span>                <span class="ID">file</span><span class="Operator">.</span><span class="ID">close</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 183 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">statusbar</span><span class="Operator">.</span><span class="ID">SetStatusText</span><span class="Operator">(</span><span class="ID">os</span><span class="Operator">.</span><span class="ID">path</span><span class="Operator">.</span><span class="ID">basename</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">last_name_saved</span><span class="Operator">)</span> <span class="Operator">+</span> <span class="String">' saved'</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 184 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">modify</span> <span class="Operator">=</span> <span class="ID">False</span></span>
<span class="line"><span class="LineNumber"> 185 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">statusbar</span><span class="Operator">.</span><span class="ID">SetStatusText</span><span class="Operator">(</span><span class="String">''</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 186 </span></span>
<span class="line"><span class="LineNumber"> 187 </span>            <span class="ResWord">except</span> <span class="ID">IOError</span><span class="Operator">,</span> <span class="ID">error</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 188 </span>                <span class="ID">dlg</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MessageDialog</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="String">'Error saving file\n'</span> <span class="Operator">+</span> <span class="ID">str</span><span class="Operator">(</span><span class="ID">error</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 189 </span>                <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">ShowModal</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 190 </span>        <span class="ResWord">else</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 191 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnSaveAsFile</span><span class="Operator">(</span><span class="ID">event</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 192 </span></span>
<span class="line"><span class="LineNumber"> 193 </span>    <span class="ResWord">def</span> <span class="ID">OnSaveAsFile</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 194 </span>        <span class="ID">wcd</span><span class="Operator">=</span><span class="String">'All files(*)|*|Editor files (*.ef)|*.ef|'</span></span>
<span class="line"><span class="LineNumber"> 195 </span>        <span class="ID">dir</span> <span class="Operator">=</span> <span class="ID">os</span><span class="Operator">.</span><span class="ID">getcwd</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 196 </span>        <span class="ID">save_dlg</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">FileDialog</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">message</span><span class="Operator">=</span><span class="String">'Save file as...'</span><span class="Operator">,</span> <span class="ID">defaultDir</span><span class="Operator">=</span><span class="ID">dir</span><span class="Operator">,</span> <span class="ID">defaultFile</span><span class="Operator">=</span><span class="String">''</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 197 </span>                        <span class="ID">wildcard</span><span class="Operator">=</span><span class="ID">wcd</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">SAVE</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">OVERWRITE_PROMPT</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 198 </span>        <span class="ResWord">if</span> <span class="ID">save_dlg</span><span class="Operator">.</span><span class="ID">ShowModal</span><span class="Operator">(</span><span class="Operator">)</span> <span class="Operator">==</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ID_OK</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 199 </span>            <span class="ID">path</span> <span class="Operator">=</span> <span class="ID">save_dlg</span><span class="Operator">.</span><span class="ID">GetPath</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 200 </span></span>
<span class="line"><span class="LineNumber"> 201 </span>            <span class="ResWord">try</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 202 </span>                <span class="ID">file</span> <span class="Operator">=</span> <span class="ID">open</span><span class="Operator">(</span><span class="ID">path</span><span class="Operator">,</span> <span class="String">'w'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 203 </span>                <span class="ID">text</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">text</span><span class="Operator">.</span><span class="ID">GetValue</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 204 </span>                <span class="ID">file</span><span class="Operator">.</span><span class="ID">write</span><span class="Operator">(</span><span class="ID">text</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 205 </span>                <span class="ID">file</span><span class="Operator">.</span><span class="ID">close</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 206 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">last_name_saved</span> <span class="Operator">=</span> <span class="ID">os</span><span class="Operator">.</span><span class="ID">path</span><span class="Operator">.</span><span class="ID">basename</span><span class="Operator">(</span><span class="ID">path</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 207 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">statusbar</span><span class="Operator">.</span><span class="ID">SetStatusText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">last_name_saved</span> <span class="Operator">+</span> <span class="String">' saved'</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 208 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">modify</span> <span class="Operator">=</span> <span class="ID">False</span></span>
<span class="line"><span class="LineNumber"> 209 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">statusbar</span><span class="Operator">.</span><span class="ID">SetStatusText</span><span class="Operator">(</span><span class="String">''</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 210 </span></span>
<span class="line"><span class="LineNumber"> 211 </span>            <span class="ResWord">except</span> <span class="ID">IOError</span><span class="Operator">,</span> <span class="ID">error</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 212 </span>                <span class="ID">dlg</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MessageDialog</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="String">'Error saving file\n'</span> <span class="Operator">+</span> <span class="ID">str</span><span class="Operator">(</span><span class="ID">error</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 213 </span>                <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">ShowModal</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 214 </span>        <span class="ID">save_dlg</span><span class="Operator">.</span><span class="ID">Destroy</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 215 </span></span>
<span class="line"><span class="LineNumber"> 216 </span>    <span class="ResWord">def</span> <span class="ID">OnCut</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 217 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">text</span><span class="Operator">.</span><span class="ID">Cut</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 218 </span></span>
<span class="line"><span class="LineNumber"> 219 </span>    <span class="ResWord">def</span> <span class="ID">OnCopy</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 220 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">text</span><span class="Operator">.</span><span class="ID">Copy</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 221 </span></span>
<span class="line"><span class="LineNumber"> 222 </span>    <span class="ResWord">def</span> <span class="ID">OnPaste</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 223 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">text</span><span class="Operator">.</span><span class="ID">Paste</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 224 </span></span>
<span class="line"><span class="LineNumber"> 225 </span>    <span class="ResWord">def</span> <span class="ID">QuitApplication</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 226 </span>        <span class="ResWord">if</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">modify</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 227 </span>            <span class="ID">dlg</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MessageDialog</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="String">'Save before Exit?'</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">YES_NO</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">YES_DEFAULT</span> <span class="Operator">|</span></span>
<span class="line"><span class="LineNumber"> 228 </span>                        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">CANCEL</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ICON_QUESTION</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 229 </span>            <span class="ID">val</span> <span class="Operator">=</span> <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">ShowModal</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 230 </span>            <span class="ResWord">if</span> <span class="ID">val</span> <span class="Operator">==</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ID_YES</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 231 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnSaveFile</span><span class="Operator">(</span><span class="ID">event</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 232 </span>                <span class="ResWord">if</span> <span class="ResWord">not</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">modify</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 233 </span>                    <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Exit</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 234 </span>            <span class="ResWord">elif</span> <span class="ID">val</span> <span class="Operator">==</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ID_CANCEL</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 235 </span>                <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">Destroy</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 236 </span>            <span class="ResWord">else</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 237 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">Destroy</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 238 </span>        <span class="ResWord">else</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 239 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">Destroy</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 240 </span></span>
<span class="line"><span class="LineNumber"> 241 </span>    <span class="ResWord">def</span> <span class="ID">OnDelete</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 242 </span>        <span class="ID">frm</span><span class="Operator">,</span> <span class="ID">to</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">text</span><span class="Operator">.</span><span class="ID">GetSelection</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 243 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">text</span><span class="Operator">.</span><span class="ID">Remove</span><span class="Operator">(</span><span class="ID">frm</span><span class="Operator">,</span> <span class="ID">to</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 244 </span></span>
<span class="line"><span class="LineNumber"> 245 </span>    <span class="ResWord">def</span> <span class="ID">OnSelectAll</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 246 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">text</span><span class="Operator">.</span><span class="ID">SelectAll</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 247 </span></span>
<span class="line"><span class="LineNumber"> 248 </span>    <span class="ResWord">def</span> <span class="ID">OnTextChanged</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 249 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">modify</span> <span class="Operator">=</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber"> 250 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">statusbar</span><span class="Operator">.</span><span class="ID">SetStatusText</span><span class="Operator">(</span><span class="String">' modified'</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 251 </span>        <span class="ID">event</span><span class="Operator">.</span><span class="ID">Skip</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 252 </span></span>
<span class="line"><span class="LineNumber"> 253 </span>    <span class="ResWord">def</span> <span class="ID">OnKeyDown</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 254 </span>        <span class="ID">keycode</span> <span class="Operator">=</span> <span class="ID">event</span><span class="Operator">.</span><span class="ID">GetKeyCode</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 255 </span>        <span class="ResWord">if</span> <span class="ID">keycode</span> <span class="Operator">==</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">WXK_INSERT</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 256 </span>            <span class="ResWord">if</span> <span class="ResWord">not</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">replace</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 257 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">statusbar</span><span class="Operator">.</span><span class="ID">SetStatusText</span><span class="Operator">(</span><span class="String">'INS'</span><span class="Operator">,</span> <span class="Number">2</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 258 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">replace</span> <span class="Operator">=</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber"> 259 </span>            <span class="ResWord">else</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 260 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">statusbar</span><span class="Operator">.</span><span class="ID">SetStatusText</span><span class="Operator">(</span><span class="String">''</span><span class="Operator">,</span> <span class="Number">2</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 261 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">replace</span> <span class="Operator">=</span> <span class="ID">False</span></span>
<span class="line"><span class="LineNumber"> 262 </span>        <span class="ID">event</span><span class="Operator">.</span><span class="ID">Skip</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 263 </span></span>
<span class="line"><span class="LineNumber"> 264 </span>    <span class="ResWord">def</span> <span class="ID">ToggleStatusBar</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 265 </span>        <span class="ResWord">if</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">statusbar</span><span class="Operator">.</span><span class="ID">IsShown</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 266 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">statusbar</span><span class="Operator">.</span><span class="ID">Hide</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 267 </span>        <span class="ResWord">else</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 268 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">statusbar</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 269 </span></span>
<span class="line"><span class="LineNumber"> 270 </span>    <span class="ResWord">def</span> <span class="ID">StatusBar</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 271 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">statusbar</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">CreateStatusBar</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 272 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">statusbar</span><span class="Operator">.</span><span class="ID">SetFieldsCount</span><span class="Operator">(</span><span class="Number">3</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 273 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">statusbar</span><span class="Operator">.</span><span class="ID">SetStatusWidths</span><span class="Operator">(</span><span class="Operator">[</span><span class="Operator">-</span><span class="Number">5</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">2</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">]</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 274 </span></span>
<span class="line"><span class="LineNumber"> 275 </span>    <span class="ResWord">def</span> <span class="ID">OnAbout</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 276 </span>        <span class="ID">dlg</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">MessageDialog</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="String">'\tEditor\t\n Another Tutorial\njan bodnar 2005-2006'</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 277 </span>                                <span class="String">'About Editor'</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">OK</span> <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ICON_INFORMATION</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 278 </span>        <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">ShowModal</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 279 </span>        <span class="ID">dlg</span><span class="Operator">.</span><span class="ID">Destroy</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 280 </span></span>
<span class="line"><span class="LineNumber"> 281 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 282 </span><span class="ID">Editor</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Editor'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 283 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-5363"></span><p class="line867"><img alt="editor.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_002.png" title="editor.png"> <span class="anchor" id="line-5364"></span><span class="anchor" id="line-5365"></span></p><p class="line867"><strong>Figure: Editor</strong> <span class="anchor" id="line-5366"></span><span class="anchor" id="line-5367"></span></p><p class="line867">
</p><h3 id="Kika">Kika</h3>
<span class="anchor" id="line-5368"></span><p class="line874">Kika is a 
gript that connects to an ftp site. If a login is successfull, Kika 
shows a connected icon on the statusbar. Otherwise, a disconnected icon 
is displayed.  We use an ftplib module from the python standard library.
  If you do not have an ftp account, you can try to login to some 
anonymous ftp sites. <span class="anchor" id="line-5369"></span><span class="anchor" id="line-5370"></span></p><p class="line867"><span class="anchor" id="line-5371"></span><span class="anchor" id="line-5372"></span><span class="anchor" id="line-5373"></span><span class="anchor" id="line-5374"></span><span class="anchor" id="line-5375"></span><span class="anchor" id="line-5376"></span><span class="anchor" id="line-5377"></span><span class="anchor" id="line-5378"></span><span class="anchor" id="line-5379"></span><span class="anchor" id="line-5380"></span><span class="anchor" id="line-5381"></span><span class="anchor" id="line-5382"></span><span class="anchor" id="line-5383"></span><span class="anchor" id="line-5384"></span><span class="anchor" id="line-5385"></span><span class="anchor" id="line-5386"></span><span class="anchor" id="line-5387"></span><span class="anchor" id="line-5388"></span><span class="anchor" id="line-5389"></span><span class="anchor" id="line-5390"></span><span class="anchor" id="line-5391"></span><span class="anchor" id="line-5392"></span><span class="anchor" id="line-5393"></span><span class="anchor" id="line-5394"></span><span class="anchor" id="line-5395"></span><span class="anchor" id="line-5396"></span><span class="anchor" id="line-5397"></span><span class="anchor" id="line-5398"></span><span class="anchor" id="line-5399"></span><span class="anchor" id="line-5400"></span><span class="anchor" id="line-5401"></span><span class="anchor" id="line-5402"></span><span class="anchor" id="line-5403"></span><span class="anchor" id="line-5404"></span><span class="anchor" id="line-5405"></span><span class="anchor" id="line-5406"></span><span class="anchor" id="line-5407"></span><span class="anchor" id="line-5408"></span><span class="anchor" id="line-5409"></span><span class="anchor" id="line-5410"></span><span class="anchor" id="line-5411"></span><span class="anchor" id="line-5412"></span><span class="anchor" id="line-5413"></span><span class="anchor" id="line-5414"></span><span class="anchor" id="line-5415"></span><span class="anchor" id="line-5416"></span><span class="anchor" id="line-5417"></span><span class="anchor" id="line-5418"></span><span class="anchor" id="line-5419"></span><span class="anchor" id="line-5420"></span><span class="anchor" id="line-5421"></span><span class="anchor" id="line-5422"></span><span class="anchor" id="line-5423"></span><span class="anchor" id="line-5424"></span><span class="anchor" id="line-5425"></span><span class="anchor" id="line-5426"></span><span class="anchor" id="line-5427"></span><span class="anchor" id="line-5428"></span><span class="anchor" id="line-5429"></span><span class="anchor" id="line-5430"></span><span class="anchor" id="line-5431"></span><span class="anchor" id="line-5432"></span><span class="anchor" id="line-5433"></span><span class="anchor" id="line-5434"></span><span class="anchor" id="line-5435"></span><span class="anchor" id="line-5436"></span><span class="anchor" id="line-5437"></span><span class="anchor" id="line-5438"></span><span class="anchor" id="line-5439"></span><span class="anchor" id="line-5440"></span><span class="anchor" id="line-5441"></span><span class="anchor" id="line-5442"></span><span class="anchor" id="line-5443"></span><span class="anchor" id="line-5444"></span><span class="anchor" id="line-5445"></span><span class="anchor" id="line-5446"></span><span class="anchor" id="line-5447"></span><span class="anchor" id="line-5448"></span><span class="anchor" id="line-5449"></span><span class="anchor" id="line-5450"></span><span class="anchor" id="line-5451"></span><span class="anchor" id="line-5452"></span><span class="anchor" id="line-5453"></span><span class="anchor" id="line-5454"></span><span class="anchor" id="line-5455"></span><span class="anchor" id="line-5456"></span><span class="anchor" id="line-5457"></span><span class="anchor" id="line-5458"></span><span class="anchor" id="line-5459"></span><span class="anchor" id="line-5460"></span></p><div class="codearea" dir="ltr" lang="en">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-ee1aea4bc65c1fb222043db4d94256b50a021341\', 1, 1);" \
                class="codenumbers">Toggle line numbers<\/a>');
</script><a href="#" onclick="return togglenumber('CA-ee1aea4bc65c1fb222043db4d94256b50a021341', 1, 1);" class="codenumbers">Toggle line numbers</a>
<pre dir="ltr" id="CA-ee1aea4bc65c1fb222043db4d94256b50a021341" lang="en"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#!/usr/bin/python</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="Comment"># kika.py</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="Comment"></span></span>
<span class="line"><span class="LineNumber">   5 </span><span class="ResWord">from</span> <span class="ID">ftplib</span> <span class="ResWord">import</span> <span class="ID">FTP</span><span class="Operator">,</span> <span class="ID">all_errors</span></span>
<span class="line"><span class="LineNumber">   6 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   7 </span></span>
<span class="line"><span class="LineNumber">   8 </span><span class="ResWord">class</span> <span class="ID">MyStatusBar</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">StatusBar</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   9 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  10 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StatusBar</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  11 </span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetFieldsCount</span><span class="Operator">(</span><span class="Number">2</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetStatusText</span><span class="Operator">(</span><span class="String">'Welcome to Kika'</span><span class="Operator">,</span> <span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetStatusWidths</span><span class="Operator">(</span><span class="Operator">[</span><span class="Operator">-</span><span class="Number">5</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">2</span><span class="Operator">]</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">icon</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticBitmap</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bitmap</span><span class="Operator">(</span><span class="String">'icons/disconnected.png'</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_SIZE</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnSize</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">PlaceIcon</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  18 </span></span>
<span class="line"><span class="LineNumber">  19 </span>    <span class="ResWord">def</span> <span class="ID">PlaceIcon</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  20 </span>        <span class="ID">rect</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">GetFieldRect</span><span class="Operator">(</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  21 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">icon</span><span class="Operator">.</span><span class="ID">SetPosition</span><span class="Operator">(</span><span class="Operator">(</span><span class="ID">rect</span><span class="Operator">.</span><span class="ID">x</span><span class="Operator">+</span><span class="Number">3</span><span class="Operator">,</span> <span class="ID">rect</span><span class="Operator">.</span><span class="ID">y</span><span class="Operator">+</span><span class="Number">3</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  22 </span></span>
<span class="line"><span class="LineNumber">  23 </span>    <span class="ResWord">def</span> <span class="ID">OnSize</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  24 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">PlaceIcon</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  25 </span></span>
<span class="line"><span class="LineNumber">  26 </span></span>
<span class="line"><span class="LineNumber">  27 </span><span class="ResWord">class</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  28 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  29 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">250</span><span class="Operator">,</span> <span class="Number">270</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  30 </span></span>
<span class="line"><span class="LineNumber">  31 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Ftp site'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">10</span><span class="Operator">,</span> <span class="Number">20</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  32 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Login'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">10</span><span class="Operator">,</span> <span class="Number">60</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  33 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">StaticText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Password'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">10</span><span class="Operator">,</span> <span class="Number">100</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  34 </span></span>
<span class="line"><span class="LineNumber">  35 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">ftpsite</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TextCtrl</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">,</span>  <span class="Operator">(</span><span class="Number">110</span><span class="Operator">,</span> <span class="Number">15</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">120</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  36 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">login</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TextCtrl</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">,</span>  <span class="Operator">(</span><span class="Number">110</span><span class="Operator">,</span> <span class="Number">55</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">120</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  37 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">password</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TextCtrl</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">''</span><span class="Operator">,</span>  <span class="Operator">(</span><span class="Number">110</span><span class="Operator">,</span> <span class="Number">95</span><span class="Operator">)</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">120</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">)</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">TE_PASSWORD</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  38 </span></span>
<span class="line"><span class="LineNumber">  39 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">ftp</span> <span class="Operator">=</span> <span class="ID">None</span></span>
<span class="line"><span class="LineNumber">  40 </span></span>
<span class="line"><span class="LineNumber">  41 </span>        <span class="ID">con</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">,</span> <span class="String">'Connect'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">10</span><span class="Operator">,</span> <span class="Number">160</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  42 </span>        <span class="ID">discon</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Button</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="Number">2</span><span class="Operator">,</span> <span class="String">'DisConnect'</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">120</span><span class="Operator">,</span> <span class="Number">160</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  43 </span></span>
<span class="line"><span class="LineNumber">  44 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnConnect</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  45 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_BUTTON</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnDisConnect</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Number">2</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  46 </span></span>
<span class="line"><span class="LineNumber">  47 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">statusbar</span> <span class="Operator">=</span> <span class="ID">MyStatusBar</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  48 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">SetStatusBar</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">.</span><span class="ID">statusbar</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  49 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Centre</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  50 </span></span>
<span class="line"><span class="LineNumber">  51 </span>    <span class="ResWord">def</span> <span class="ID">OnConnect</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  52 </span>        <span class="ResWord">if</span> <span class="ResWord">not</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">ftp</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  53 </span>            <span class="ID">ftpsite</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">ftpsite</span><span class="Operator">.</span><span class="ID">GetValue</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  54 </span>            <span class="ID">login</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">login</span><span class="Operator">.</span><span class="ID">GetValue</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  55 </span>            <span class="ID">password</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">password</span><span class="Operator">.</span><span class="ID">GetValue</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  56 </span></span>
<span class="line"><span class="LineNumber">  57 </span>            <span class="ResWord">try</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  58 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">ftp</span> <span class="Operator">=</span> <span class="ID">FTP</span><span class="Operator">(</span><span class="ID">ftpsite</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  59 </span>                <span class="ID">var</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">ftp</span><span class="Operator">.</span><span class="ID">login</span><span class="Operator">(</span><span class="ID">login</span><span class="Operator">,</span> <span class="ID">password</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  60 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">statusbar</span><span class="Operator">.</span><span class="ID">SetStatusText</span><span class="Operator">(</span><span class="String">'User connected'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  61 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">statusbar</span><span class="Operator">.</span><span class="ID">icon</span><span class="Operator">.</span><span class="ID">SetBitmap</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bitmap</span><span class="Operator">(</span><span class="String">'icons/connected.png'</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  62 </span></span>
<span class="line"><span class="LineNumber">  63 </span>            <span class="ResWord">except</span> <span class="ID">AttributeError</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  64 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">statusbar</span><span class="Operator">.</span><span class="ID">SetForegroundColour</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">RED</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  65 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">statusbar</span><span class="Operator">.</span><span class="ID">SetStatusText</span><span class="Operator">(</span><span class="String">'Incorrect params'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  66 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">ftp</span> <span class="Operator">=</span> <span class="ID">None</span></span>
<span class="line"><span class="LineNumber">  67 </span></span>
<span class="line"><span class="LineNumber">  68 </span>            <span class="ResWord">except</span> <span class="ID">all_errors</span><span class="Operator">,</span> <span class="ID">err</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  69 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">statusbar</span><span class="Operator">.</span><span class="ID">SetStatusText</span><span class="Operator">(</span><span class="ID">str</span><span class="Operator">(</span><span class="ID">err</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  70 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">ftp</span> <span class="Operator">=</span> <span class="ID">None</span></span>
<span class="line"><span class="LineNumber">  71 </span></span>
<span class="line"><span class="LineNumber">  72 </span>    <span class="ResWord">def</span> <span class="ID">OnDisConnect</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">event</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  73 </span>        <span class="ResWord">if</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">ftp</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  74 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">ftp</span><span class="Operator">.</span><span class="ID">quit</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  75 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">ftp</span> <span class="Operator">=</span> <span class="ID">None</span></span>
<span class="line"><span class="LineNumber">  76 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">statusbar</span><span class="Operator">.</span><span class="ID">SetStatusText</span><span class="Operator">(</span><span class="String">'User disconnected'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  77 </span>            <span class="ID">self</span><span class="Operator">.</span><span class="ID">statusbar</span><span class="Operator">.</span><span class="ID">icon</span><span class="Operator">.</span><span class="ID">SetBitmap</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Bitmap</span><span class="Operator">(</span><span class="String">'icons/disconnected.png'</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  78 </span></span>
<span class="line"><span class="LineNumber">  79 </span><span class="ResWord">class</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">App</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  80 </span>    <span class="ResWord">def</span> <span class="ID">OnInit</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  81 </span>        <span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">MyFrame</span><span class="Operator">(</span><span class="ID">None</span><span class="Operator">,</span> <span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="String">'Kika'</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  82 </span>        <span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  83 </span>        <span class="ResWord">return</span> <span class="ID">True</span></span>
<span class="line"><span class="LineNumber">  84 </span></span>
<span class="line"><span class="LineNumber">  85 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">MyApp</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  86 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre></div><span class="anchor" id="line-5461"></span><p class="line874">Notice that each time the window is resized, we must position our icon to a new place. <span class="anchor" id="line-5462"></span><span class="anchor" id="line-5463"></span></p><p class="line867"><span class="anchor" id="line-5464"></span><span class="anchor" id="line-5465"></span><span class="anchor" id="line-5466"></span><span class="anchor" id="line-5467"></span></p><pre>def PlaceIcon(self):
    rect = self.GetFieldRect(1)
    self.icon.SetPosition((rect.x+3, rect.y+3))</pre><span class="anchor" id="line-5468"></span><p class="line867"><img alt="kika.png" class="attachment" src="AnotherTutorial_files/AnotherTutorial_048.png" title="kika.png"> <span class="anchor" id="line-5469"></span><span class="anchor" id="line-5470"></span></p><p class="line867"><strong>Figure: Kika</strong> <span class="anchor" id="line-5471"></span><span class="anchor" id="line-5472"></span></p><p class="line867">
</p><h2 id="Appendix">Appendix</h2>
<span class="anchor" id="line-5473"></span><p class="line867">
</p><h3 id="Cursor_IDs">Cursor IDs</h3>
<span class="anchor" id="line-5474"></span><div><table><tbody><tr>  <td><p class="line862">wx.CURSOR_ARROW </p></td>
  <td><p class="line862">wx.CURSOR_RIGHT_ARROW </p></td>
  <td><p class="line862">wx.CURSOR_BLANK </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5475"></span><p class="line862">wx.CURSOR_BULLSEYE </p></td>
  <td><p class="line862">wx.CURSOR_CHAR </p></td>
  <td><p class="line862">wx.CURSOR_CROSS </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5476"></span><p class="line862">wx.CURSOR_HAND </p></td>
  <td><p class="line862">wx.CURSOR_IBEAM </p></td>
  <td><p class="line862">wx.CURSOR_LEFT_BUTTON </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5477"></span><p class="line862">wx.CURSOR_MAGNIFIER </p></td>
  <td><p class="line862">wx.CURSOR_MIDDLE_BUTTON </p></td>
  <td><p class="line862">wx.CURSOR_NO_ENTRY </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5478"></span><p class="line862">wx.CURSOR_PAINT_BRUSH </p></td>
  <td><p class="line862">wx.CURSOR_PENCIL </p></td>
  <td><p class="line862">wx.CURSOR_POINT_LEFT </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5479"></span><p class="line862">wx.CURSOR_POINT_RIGHT </p></td>
  <td><p class="line862">wx.CURSOR_QUESTION_ARROW </p></td>
  <td><p class="line862">wx.CURSOR_RIGHT_BUTTON </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5480"></span><p class="line862">wx.CURSOR_SIZENESW </p></td>
  <td><p class="line862">wx.CURSOR_SIZENS </p></td>
  <td><p class="line862">wx.CURSOR_SIZENWSE </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5481"></span><p class="line862">wx.CURSOR_SIZEWE </p></td>
  <td><p class="line862">wx.CURSOR_SIZING </p></td>
  <td><p class="line862">wx.CURSOR_SPRAYCAN </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5482"></span><p class="line862">wx.CURSOR_WAIT </p></td>
  <td><p class="line862">wx.CURSOR_WATCH </p></td>
  <td><p class="line862">wx.CURSOR_ARROWWAIT </p></td>
</tr>
</tbody></table></div><span class="anchor" id="line-5483"></span><span class="anchor" id="line-5484"></span><span class="anchor" id="line-5485"></span><p class="line867">
</p><h3 id="wx.Frame_styles">wx.Frame styles</h3>
<span class="anchor" id="line-5486"></span><div><table><tbody><tr>  <td><p class="line862">wx.DEFAULT_FRAME_STYLE </p></td>
  <td><p class="line862">wx.ICONIZE </p></td>
  <td><p class="line862">wx.FRAME_SHAPED </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5487"></span><p class="line862">wx.CAPTION </p></td>
  <td><p class="line862">wx.MINIMIZE </p></td>
  <td><p class="line862">wx.MINIMIZE_BOX </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5488"></span><p class="line862">wx.MAXIMIZE </p></td>
  <td><p class="line862">wx.MAXIMIZE_BOX </p></td>
  <td><p class="line862">wx.STAY_ON_TOP </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5489"></span><p class="line862">wx.SYSTEM_MENU </p></td>
  <td><p class="line862">wx.SIMPLE_BORDER </p></td>
  <td><p class="line862">wx.RESIZE_BORDER </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5490"></span><p class="line862">wx.FRAME_TOOL_WINDOW </p></td>
  <td><p class="line862">wx.FRAME_NO_TASKBAR </p></td>
  <td><p class="line862">wx.FRAME_FLOAT_ON_PARENT </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5491"></span><p class="line862">wx.FRAME_EX_CONTEXTHELP </p></td>
  <td><p class="line862"> </p></td>
  <td><p class="line862"> </p></td>
</tr>
</tbody></table></div><span class="anchor" id="line-5492"></span><span class="anchor" id="line-5493"></span><span class="anchor" id="line-5494"></span><p class="line867">
</p><h3 id="Standard_Colour_Database">Standard Colour Database</h3>
<span class="anchor" id="line-5495"></span><div><table><tbody><tr>  <td><p class="line862">AQUAMARINE </p></td>
  <td><p class="line862">BLACK </p></td>
  <td><p class="line862">BLUE </p></td>
  <td><p class="line862">BLUE VIOLET </p></td>
  <td><p class="line862">BROWN </p></td>
  <td><p class="line862">CADET BLUE </p></td>
  <td><p class="line862">CORAL </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5496"></span><p class="line862">CORNFLOWER BLUE </p></td>
  <td><p class="line862">CYAN </p></td>
  <td><p class="line862">DARK GREY </p></td>
  <td><p class="line862">DARK GREEN </p></td>
  <td><p class="line862">DARK OLIVE GREEN </p></td>
  <td><p class="line862">DARK ORCHID </p></td>
  <td><p class="line862">DARK SLATE BLUE </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5497"></span><p class="line862">DARK SLATE GREY </p></td>
  <td><p class="line862">DARK TURQUOISE </p></td>
  <td><p class="line862">DIM GREY </p></td>
  <td><p class="line862">FIREBRICK </p></td>
  <td><p class="line862">FOREST GREEN </p></td>
  <td><p class="line862">GOLD </p></td>
  <td><p class="line862">GOLDENROD </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5498"></span><p class="line862">GREY </p></td>
  <td><p class="line862">GREEN </p></td>
  <td><p class="line862">GREEN YELLOW </p></td>
  <td><p class="line862">INDIAN RED </p></td>
  <td><p class="line862">KHAKI </p></td>
  <td><p class="line862">LIGHT BLUE </p></td>
  <td><p class="line862">LIGHT GREY </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5499"></span><p class="line862">LIGHT STEEL BLUE </p></td>
  <td><p class="line862">LIME GREEN </p></td>
  <td><p class="line862">MAGENTA </p></td>
  <td><p class="line862">MAROON </p></td>
  <td><p class="line862">MEDIUM AQUAMARINE </p></td>
  <td><p class="line862">MEDIUM BLUE </p></td>
  <td><p class="line862">MEDIUM FOREST GREEN </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5500"></span><p class="line862">MEDIUM GOLDENROD </p></td>
  <td><p class="line862">MEDIUM ORCHID </p></td>
  <td><p class="line862">MEDIUM SEA GREEN </p></td>
  <td><p class="line862">MEDIUM SLATE BLUE </p></td>
  <td><p class="line862">MEDIUM SPRING GREEN </p></td>
  <td><p class="line862">MEDIUM TURQUOISE </p></td>
  <td><p class="line862">MEDIUM VIOLET RED </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5501"></span><p class="line862">MIDNIGHT BLUE </p></td>
  <td><p class="line862">NAVY </p></td>
  <td><p class="line862">ORANGE </p></td>
  <td><p class="line862">ORANGE RED </p></td>
  <td><p class="line862">ORCHID </p></td>
  <td><p class="line862">PALE GREEN </p></td>
  <td><p class="line862">PINK </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5502"></span><p class="line862">PLUM </p></td>
  <td><p class="line862">PURPLE </p></td>
  <td><p class="line862">RED </p></td>
  <td><p class="line862">SALMON </p></td>
  <td><p class="line862">SEA GREEN </p></td>
  <td><p class="line862">SIENNA </p></td>
  <td><p class="line862">SKY BLUE </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5503"></span><p class="line862">SLATE BLUE </p></td>
  <td><p class="line862">SPRING GREEN </p></td>
  <td><p class="line862">STEEL BLUE </p></td>
  <td><p class="line862">TAN </p></td>
  <td><p class="line862">THISTLE </p></td>
  <td><p class="line862">TURQUOISE </p></td>
  <td><p class="line862">VIOLET </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5504"></span><p class="line862">VIOLET RED </p></td>
  <td><p class="line862">WHEAT </p></td>
  <td><p class="line862">WHITE </p></td>
  <td><p class="line862">YELLOW </p></td>
  <td><p class="line862">YELLOW GREEN </p></td>
</tr>
</tbody></table></div><span class="anchor" id="line-5505"></span><span class="anchor" id="line-5506"></span><span class="anchor" id="line-5507"></span><p class="line867">
</p><h3 id="wx.Pen_styles">wx.Pen styles</h3>
<span class="anchor" id="line-5508"></span><div><table><tbody><tr>  <td><p class="line862">wx.SOLID </p></td>
  <td><p class="line862">wx.TRANSPARENT </p></td>
  <td><p class="line862">wx.DOT </p></td>
  <td><p class="line862">wx.LONG_DASH </p></td>
  <td><p class="line862">wx.SHORT_DASH </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5509"></span><p class="line862">wx.DOT_DASH </p></td>
  <td><p class="line862">wx.STIPPLE </p></td>
  <td><p class="line862">wx.USER_DASH </p></td>
  <td><p class="line862">wx.BDIAGONAL_HATCH </p></td>
  <td><p class="line862">wx.CROSSDIAG_HATCH </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5510"></span><p class="line862">wx.FDIAGONAL_HATCH </p></td>
  <td><p class="line862">wx.CROSS_HATCH </p></td>
  <td><p class="line862">wx.HORIZONTAL_HATCH </p></td>
  <td><p class="line862">wx.VERTICAL_HATCH </p></td>
</tr>
</tbody></table></div><span class="anchor" id="line-5511"></span><span class="anchor" id="line-5512"></span><span class="anchor" id="line-5513"></span><p class="line867">
</p><h3 id="wx.Brush_styles">wx.Brush styles</h3>
<span class="anchor" id="line-5514"></span><div><table><tbody><tr>  <td><p class="line862">wx.BLUE_BRUSH </p></td>
  <td><p class="line862">wx.GREEN_BRUSH </p></td>
  <td><p class="line862">wx.WHITE_BRUSH </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5515"></span><p class="line862">wx.BLACK_BRUSH </p></td>
  <td><p class="line862">wx.GREY_BRUSH </p></td>
  <td><p class="line862">wx.MEDIUM_GREY_BRUSH </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5516"></span><p class="line862">wx.LIGHT_GREY_BRUSH </p></td>
  <td><p class="line862">wx.TRANSPARENT_BRUSH </p></td>
  <td><p class="line862">wx.CYAN_BRUSH </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5517"></span><p class="line862">wx.RED_BRUSH </p></td>
</tr>
</tbody></table></div><span class="anchor" id="line-5518"></span><span class="anchor" id="line-5519"></span><span class="anchor" id="line-5520"></span><p class="line867">
</p><h3 id="CalendarCtrl_styles">CalendarCtrl styles</h3>
<span class="anchor" id="line-5521"></span><div><table><tbody><tr>  <td><p class="line862">CAL_SUNDAY_FIRST </p></td>
  <td><p class="line862">CAL_MONDAY_FIRST </p></td>
  <td><p class="line862">CAL_SHOW_HOLIDAYS </p></td>
  <td><p class="line862">CAL_NO_YEAR_CHANGE </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5522"></span><p class="line862">CAL_NO_MONTH_CHANGE </p></td>
  <td><p class="line862">CAL_SEQUENTIAL_MONTH_SELECTION </p></td>
  <td><p class="line862">CAL_SHOW_SURROUNDING_WEEKS </p></td>
  <td><p class="line862">CAL_HITTEST_NOWHERE </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5523"></span><p class="line862">CAL_HITTEST_HEADER </p></td>
  <td><p class="line862">CAL_HITTEST_DAY </p></td>
  <td><p class="line862">CAL_HITTEST_INCMONTH </p></td>
  <td colspan="2" style="text-align: center;"><p class="line862">CAL_HITTEST_DECMONTH </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5524"></span><p class="line862">CAL_HITTEST_SURROUNDING_WEEK </p></td>
  <td><p class="line862">CAL_BORDER_NONE </p></td>
  <td><p class="line862">CAL_BORDER_SQUARE </p></td>
  <td><p class="line862">CAL_BORDER_ROUND </p></td>
</tr>
</tbody></table></div><span class="anchor" id="line-5525"></span><span class="anchor" id="line-5526"></span><span class="anchor" id="line-5527"></span><p class="line867">
</p><h3 id="Keycodes">Keycodes</h3>
<span class="anchor" id="line-5528"></span><div><table><tbody><tr>  <td><p class="line862">WXK_BACK </p></td>
  <td><p class="line862">WXK_TAB </p></td>
  <td><p class="line862">WXK_RETURN </p></td>
  <td><p class="line862">WXK_ESCAPE </p></td>
  <td><p class="line862">WXK_SPACE </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5529"></span><p class="line862">WXK_DELETE </p></td>
  <td><p class="line862">WXK_START </p></td>
  <td><p class="line862">WXK_LBUTTON </p></td>
  <td><p class="line862">WXK_RBUTTON </p></td>
  <td><p class="line862">WXK_CANCEL </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5530"></span><p class="line862">WXK_MBUTTON </p></td>
  <td><p class="line862">WXK_CLEAR </p></td>
  <td><p class="line862">WXK_SHIFT </p></td>
  <td><p class="line862">WXK_CONTROL </p></td>
  <td><p class="line862">WXK_MENU </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5531"></span><p class="line862">WXK_PAUSE </p></td>
  <td><p class="line862">WXK_CAPITAL </p></td>
  <td><p class="line862">WXK_PRIOR </p></td>
  <td><p class="line862">WXK_NEXT </p></td>
  <td><p class="line862">WXK_END </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5532"></span><p class="line862">WXK_HOME </p></td>
  <td><p class="line862">WXK_LEFT </p></td>
  <td><p class="line862">WXK_UP </p></td>
  <td><p class="line862">WXK_RIGHT </p></td>
  <td><p class="line862">WXK_DOWN </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5533"></span><p class="line862">WXK_SELECT </p></td>
  <td><p class="line862">WXK_PRINT </p></td>
  <td><p class="line862">WXK_EXECUTE </p></td>
  <td><p class="line862">WXK_SNAPSHOT </p></td>
  <td><p class="line862">WXK_INSERT </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5534"></span><p class="line862">WXK_HELP </p></td>
  <td><p class="line862">WXK_NUMPAD0 </p></td>
  <td><p class="line862">WXK_NUMPAD1 </p></td>
  <td><p class="line862">WXK_NUMPAD2 </p></td>
  <td><p class="line862">WXK_NUMPAD3 </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5535"></span><p class="line862">WXK_NUMPAD4 </p></td>
  <td><p class="line862">WXK_NUMPAD5 </p></td>
  <td><p class="line862">WXK_NUMPAD6 </p></td>
  <td><p class="line862">WXK_NUMPAD7 </p></td>
  <td><p class="line862">WXK_NUMPAD8 </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5536"></span><p class="line862">WXK_NUMPAD9 </p></td>
  <td><p class="line862">WXK_MULTIPLY </p></td>
  <td><p class="line862">WXK_ADD </p></td>
  <td><p class="line862">WXK_SEPARATOR </p></td>
  <td><p class="line862">WXK_SUBTRACT </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5537"></span><p class="line862">WXK_DECIMAL </p></td>
  <td><p class="line862">WXK_DIVIDE </p></td>
  <td><p class="line862">WXK_F1 </p></td>
  <td><p class="line862">WXK_F2 </p></td>
  <td><p class="line862">WXK_F3 </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5538"></span><p class="line862">WXK_F4 </p></td>
  <td><p class="line862">WXK_F5 </p></td>
  <td><p class="line862">WXK_F6 </p></td>
  <td><p class="line862">WXK_F7 </p></td>
  <td><p class="line862">WXK_F8 </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5539"></span><p class="line862">WXK_F9 </p></td>
  <td><p class="line862">WXK_F10 </p></td>
  <td><p class="line862">WXK_F11 </p></td>
  <td><p class="line862">WXK_F12 </p></td>
  <td><p class="line862">WXK_F13 </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5540"></span><p class="line862">WXK_F14 </p></td>
  <td><p class="line862">WXK_F15 </p></td>
  <td><p class="line862">WXK_F16 </p></td>
  <td><p class="line862">WXK_F17 </p></td>
  <td><p class="line862">WXK_F18 </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5541"></span><p class="line862">WXK_F19 </p></td>
  <td><p class="line862">WXK_F20 </p></td>
  <td><p class="line862">WXK_F21 </p></td>
  <td><p class="line862">WXK_F22 </p></td>
  <td><p class="line862">WXK_F23 </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5542"></span><p class="line862">WXK_F24 </p></td>
  <td><p class="line862">WXK_NUMLOCK </p></td>
  <td><p class="line862">WXK_SCROLL </p></td>
  <td><p class="line862">WXK_PAGEUP </p></td>
  <td><p class="line862">WXK_PAGEDOWN </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5543"></span><p class="line862">WXK_NUMPAD_SPACE </p></td>
  <td><p class="line862">WXK_NUMPAD_TAB </p></td>
  <td><p class="line862">WXK_NUMPAD_ENTER </p></td>
  <td><p class="line862">WXK_NUMPAD_F1 </p></td>
  <td><p class="line862">WXK_NUMPAD_F2 </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5544"></span><p class="line862">WXK_NUMPAD_F3 </p></td>
  <td><p class="line862">WXK_NUMPAD_F4 </p></td>
  <td><p class="line862">WXK_NUMPAD_HOME </p></td>
  <td><p class="line862">WXK_NUMPAD_LEFT </p></td>
  <td><p class="line862">WXK_NUMPAD_UP </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5545"></span><p class="line862">WXK_NUMPAD_RIGHT </p></td>
  <td><p class="line862">WXK_NUMPAD_DOWN </p></td>
  <td><p class="line862">WXK_NUMPAD_PRIOR </p></td>
  <td><p class="line862">WXK_NUMPAD_PAGEUP </p></td>
  <td><p class="line862">WXK_NUMPAD_NEXT </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5546"></span><p class="line862">WXK_NUMPAD_PAGEDOWN </p></td>
  <td><p class="line862">WXK_NUMPAD_END </p></td>
  <td><p class="line862">WXK_NUMPAD_BEGIN </p></td>
  <td><p class="line862">WXK_NUMPAD_INSERT </p></td>
  <td><p class="line862">WXK_NUMPAD_DELETE </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5547"></span><p class="line862">WXK_NUMPAD_EQUAL </p></td>
  <td><p class="line862">WXK_NUMPAD_MULTIPLY </p></td>
  <td><p class="line862">WXK_NUMPAD_ADD </p></td>
  <td><p class="line862">WXK_NUMPAD_SEPARATOR </p></td>
</tr>
<tr>  <td><span class="anchor" id="line-5548"></span><p class="line862">WXK_NUMPAD_SUBTRACT </p></td>
  <td><p class="line862"> </p></td>
  <td><p class="line862">WXK_NUMPAD_DECIMAL </p></td>
  <td><p class="line862">WXK_NUMPAD_DIVIDE </p></td>
</tr>
</tbody></table></div><span class="anchor" id="line-5549"></span><span class="anchor" id="line-5550"></span><span class="anchor" id="line-5551"></span><p class="line867">
</p><h2 id="Comments...">Comments...</h2>
<span class="anchor" id="line-5552"></span><p class="line862">I've added a little example extending the <tt>wx.TreeCtrl</tt> example to create a  window with a  tree and moveable <span class="anchor" id="line-5553"></span>splitter window at <a href="http://wiki.wxpython.org/AnotherTutorialTreeCtrlComment">AnotherTutorialTreeCtrlComment</a>.       adil  hasan <span class="anchor" id="line-5554"></span><span class="anchor" id="bottom"></span></p></div><p id="pageinfo" class="info" dir="ltr" lang="en">AnotherTutorial  (last edited 2010-08-07 16:01:28 by <span title="RobinDunn @ c-98-246-90-205.hsd1.wa.comcast.net[98.246.90.205]"><a href="http://wiki.wxpython.org/RobinDunn" title="RobinDunn @ c-98-246-90-205.hsd1.wa.comcast.net[98.246.90.205]">RobinDunn</a></span>)</p>

<div id="pagebottom"></div>
</div>


<div id="footer">
<ul class="editbar"><li><span class="disabled">Immutable Page</span></li><li class="toggleCommentsButton" style="display: none;"><a href="#" class="nbcomment" onclick="toggleComments();return false;">Comments</a></li><li><a class="nbinfo" href="http://wiki.wxpython.org/AnotherTutorial?action=info" rel="nofollow">Info</a></li><li><a class="nbattachments" href="http://wiki.wxpython.org/AnotherTutorial?action=AttachFile" rel="nofollow">Attachments</a></li><li>
<form class="actionsmenu" method="GET" action="/AnotherTutorial">
<div>
    
    <select name="action" onchange="if ((this.selectedIndex != 0) &amp;&amp;
                      (this.options[this.selectedIndex].disabled == false)) {
                this.form.submit();
            }
            this.selectedIndex = 0;">
        <option selected="selected" value="show">More Actions:</option><option value="raw">Raw Text</option>
<option value="print">Print View</option>
<option value="RenderAsDocbook">Render as Docbook</option>
<option value="refresh">Delete Cache</option>
<option value="show" disabled="disabled" class="disabled">------------------------</option>
<option value="SpellCheck">Check Spelling</option>
<option value="LikePages">Like Pages</option>
<option value="LocalSiteMap">Local Site Map</option>
<option value="show" disabled="disabled" class="disabled">------------------------</option>
<option value="RenamePage" disabled="disabled" class="disabled">Rename Page</option>
<option value="DeletePage" disabled="disabled" class="disabled">Delete Page</option>
<option value="show" disabled="disabled" class="disabled">------------------------</option>
<option value="show" disabled="disabled" class="disabled">Subscribe User</option>
<option value="show" disabled="disabled" class="disabled">------------------------</option>
<option value="show" disabled="disabled" class="disabled">Remove Spam</option>
<option value="show" disabled="disabled" class="disabled">Revert to this revision</option>
<option value="show" disabled="disabled" class="disabled">Package Pages</option>
<option value="SyncPages">Sync Pages</option>
<option value="show" disabled="disabled" class="disabled">------------------------</option>
<option value="Load">Load</option>
<option value="Save">Save</option>
    </select>
    
    
</div>
<script type="text/javascript">
<!--// Init menu
actionsMenuInit('More Actions:');
//-->
</script>
</form>
</li></ul>

<ul id="credits">
<li><a href="http://wxpython.org/"><img src="AnotherTutorial_files/wxPyButton.png" alt="wxPython" border="0" height="43" width="100"></a></li><li><a href="http://www.python.org/"><img src="AnotherTutorial_files/PythonPowered.gif" alt="PythonPowered" border="0" height="33" width="82"></a></li><li><a href="http://sourceforge.net/projects/wxpython/"><img src="AnotherTutorial_files/sflogo.png" alt="sourceforge" border="0" height="31" width="88"></a></li><li><a href="http://www.manning.com/affiliate/idevaffiliate.php?id=189_23_1_21"><img src="AnotherTutorial_files/wxPython.gif" border="0" height="36" width="144"></a></li>
</ul>


</div>
</body></html>